Browse Source

fixing clippy warnings

master
Schneider 5 years ago
parent
commit
ad45dcd6db
  1. 6
      src/app.rs
  2. 1
      src/cache.rs
  3. 1
      src/gitignore.rs
  4. 20
      src/helpers.rs
  5. 15
      src/main.rs
  6. 8
      src/template.rs

6
src/app.rs

@ -8,10 +8,10 @@ use std::path::PathBuf;
use directories::ProjectDirs;
use structopt::StructOpt;
use log::{debug, error, info, trace, warn};
use log::{info, trace};
// Local Imports
use crate::cache::{Cache, File as FileCache};
use crate::cache::File as FileCache;
use crate::errors::*;
use crate::gitignore::Gitignore;
use crate::helpers::{git_dir, BoilerplateOpts, HELP_TEMPLATE};
@ -94,6 +94,7 @@ fn run_add(glob: &str) -> Result<()> {
/// Runs the command `get`
fn run_get(lang: &str) -> Result<()> {
trace!("Run command `get` with lang {}", &lang);
unimplemented!();
}
@ -136,7 +137,6 @@ pub fn main(opts: CliOpts) -> Result<()> {
// Tests go below the code where they'll be out of the way when not the target of attention
#[cfg(test)]
mod tests {
use super::CliOpts;
// TODO: Unit test to verify that the doc comment on `CliOpts` isn't overriding the intended
// about string.

1
src/cache.rs

@ -1,3 +1,4 @@
//! Module to implement a simple cache
use crate::errors::*;
use crate::template::GithubTemplates;
use core::time::Duration;

1
src/gitignore.rs

@ -1,3 +1,4 @@
//! This module contains an abstraction for gitignore files
use crate::errors::*;
use std::fs::OpenOptions;
use std::path::PathBuf;

20
src/helpers.rs

@ -6,12 +6,9 @@
// `#![...]` it onto the entire module.
#![allow(clippy::result_unwrap_used)]
use log::{info, trace};
use std::fs::File;
use crate::errors::*;
use std::fs::DirEntry;
use std::fs::ReadDir;
use std::path::Path;
use std::path::PathBuf;
use structopt::{clap, StructOpt};
@ -100,18 +97,3 @@ pub fn git_dir() -> Result<Option<PathBuf>> {
info!("Arrived at filesystem root while checking for git folder");
Ok(None)
}
/// Returns the path to the cache dir
///
/// If env `XDG_CACHE_HOME` is not set it uses `$HOME/.cache` and appends `gitig`. If dir does not
/// exists it will be created
pub fn cache_dir() -> PathBuf {
let root = std::env::var("XDG_CACHE_HOME").unwrap_or_else(|_| "$HOME/.cache/".to_string());
let mut root = PathBuf::from(root);
root.push("gitig");
if !root.exists() && std::fs::create_dir_all(&root).is_err() {
// should not happen, but as a fallback we can use /tmp/
root = PathBuf::from("/tmp");
}
root
}

15
src/main.rs

@ -1,4 +1,6 @@
/*! TODO: Application description here
/*! Gitig is a small cli program to handle gitignore files
It helps adding new entries to ignore and start a new project with templates from [Github](https://github.com/github/gitignore).
This project used [rust-cli-boilerplate](https://github.com/ssokolow/rust-cli-boilerplate)
*/
@ -20,12 +22,15 @@ This project used [rust-cli-boilerplate](https://github.com/ssokolow/rust-cli-bo
clippy::restriction
)]
// Opt out of the lints I've seen and don't want
#![allow(clippy::float_arithmetic, clippy::implicit_return, clippy::filter_map)]
#![allow(
clippy::float_arithmetic,
clippy::implicit_return,
clippy::filter_map,
clippy::wildcard_imports
)]
#[macro_use]
extern crate error_chain;
extern crate reqwest;
extern crate serde;
// stdlib imports
use std::convert::TryInto;
@ -33,7 +38,6 @@ use std::io;
// 3rd-party imports
mod errors;
use log::error;
use structopt::{clap, StructOpt};
// Local imports
@ -52,6 +56,7 @@ mod template;
///
/// **TODO:** Consider switching to Failure and look into `impl Termination` as a way to avoid
/// having to put the error message pretty-printing inside main()
#[allow(clippy::result_expect_used, clippy::exit, clippy::use_debug)]
fn main() {
// Parse command-line arguments (exiting on parse error, --version, or --help)
let opts = app::CliOpts::from_args();

8
src/template.rs

@ -1,6 +1,5 @@
//! This module contains structs for working with the github templates
use crate::cache::Cache;
use log::{debug, trace};
use reqwest::blocking::Client;
use reqwest::header::{ACCEPT, CONTENT_TYPE, USER_AGENT};
@ -8,13 +7,8 @@ use serde::{Deserialize, Serialize};
use crate::errors::*;
type CacheContents = Vec<Template>;
type CacheType = dyn Cache<CacheContents>;
/// Default user agent string used for api requests
pub const DEFAULT_USER_AGENT: &str = "gitig";
/// Default key used for cache
const CACHE_KEY: &str = "templates.json";
/// Response objects from github api
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -68,7 +62,7 @@ impl Template {
#[derive(Serialize, Deserialize)]
pub struct GithubTemplates {
/// The templates
templates: CacheContents,
templates: Vec<Template>,
}
impl GithubTemplates {

Loading…
Cancel
Save