-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change name dot-rs -> up-rs, migrate to anyhow/thiserror
Also bumps dependencies.
- Loading branch information
Showing
23 changed files
with
618 additions
and
912 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
[package] | ||
name = "dot-rs" | ||
name = "up-rs" | ||
version = "0.1.0" | ||
authors = ["Gibson Fahnestock <gibfahn@gmail.com>"] | ||
edition = '2018' | ||
|
||
[[bin]] | ||
name = "up" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
walkdir = "2.2.7" | ||
quicli = "0.4.0" | ||
shellexpand = "1.0.0" | ||
failure = "0.1.5" | ||
# Not a direct dependency, needed by Rust 2018 edition for some reason. | ||
structopt = "0.2.14" | ||
serde = "1.0.84" | ||
serde_derive = "1.0.84" | ||
envy = "0.3.3" | ||
toml = "0.4.10" | ||
serde_json = "1.0.35" | ||
serde_yaml = "0.8.8" | ||
walkdir = "2.3.1" | ||
shellexpand = "2.0.0" | ||
structopt = "0.3.9" | ||
serde = "1.0.104" | ||
serde_derive = "1.0.104" | ||
envy = "0.4.1" | ||
toml = "0.5.6" | ||
serde_json = "1.0.48" | ||
serde_yaml = "0.8.11" | ||
log = "0.4.8" | ||
anyhow = "1.0.26" | ||
thiserror = "1.0.11" | ||
env_logger = "0.7.1" | ||
|
||
[dev-dependencies] | ||
whoami = "0.4.1" | ||
|
||
whoami = "0.7.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use structopt::{clap::AppSettings, StructOpt}; | ||
|
||
/// Builds the Args struct from CLI input and from environment variable input. | ||
pub fn parse() -> Args { | ||
Args::from_args() | ||
} | ||
|
||
/// Up is a tool to help you manage your developer machine. When run by itself (`up`) it | ||
/// does two things. It links configuration files into the right locations, and it runs scripts to | ||
/// make sure the tools you need are installed and up to date. | ||
/// | ||
/// The `up link` command symlinks your dotfiles into your home directory. | ||
/// | ||
/// The `up date` command provides an easy way to specify what you want on your system, and how | ||
/// to keep it up to date. It is designed to work with and complement existing package | ||
/// managers rather than replace them. | ||
#[derive(Debug, StructOpt)] | ||
#[structopt(rename_all = "kebab-case")] | ||
#[structopt(global_settings = &[AppSettings::ColoredHelp])] | ||
pub struct Args { | ||
// TODO(gib): Improve help text to cover env_logger setup. | ||
/// Set the logging level explicitly (options: Off, Error, Warn, Info, Debug, Trace). | ||
#[structopt(long, default_value = "up=info,warn", env = "RUST_LOG")] | ||
pub log_level: String, | ||
/// Path to the up.toml file for up. | ||
#[structopt(short = "c", default_value = "$XDG_CONFIG_HOME/up/up.toml")] | ||
pub(crate) config: String, | ||
#[structopt(subcommand)] | ||
pub(crate) cmd: Option<SubCommand>, | ||
} | ||
|
||
// Optional subcommand (e.g. the "update" in "up update"). | ||
#[derive(Debug, StructOpt)] | ||
pub(crate) enum SubCommand { | ||
// TODO(gib): Work out how to do clap's help and long_help in structopt. | ||
/// Install and update things on your computer. | ||
#[structopt(name = "date")] | ||
Update {}, | ||
|
||
/// Symlink your dotfiles from a git repo to your home directory. | ||
#[structopt(name = "link")] | ||
Link { | ||
/// Path where your dotfiles are kept (hopefully in source control). | ||
#[structopt(short = "f", default_value = "~/code/dotfiles")] | ||
from_dir: String, | ||
/// Path to link them to. | ||
#[structopt(short = "t", default_value = "~")] | ||
to_dir: String, | ||
/// Path at which to store backups of overwritten files. | ||
#[structopt(short = "b", default_value = "~/backup")] | ||
backup_dir: String, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use anyhow::{bail, Result}; | ||
|
||
use crate::{ | ||
args::{Args, SubCommand}, | ||
config::Config, | ||
}; | ||
|
||
pub mod args; | ||
mod config; | ||
mod link; | ||
mod update; | ||
|
||
pub fn run(args: Args) -> Result<()> { | ||
// TODO(gib): Store and fetch config in config module. | ||
let config = Config::from(&args)?; | ||
|
||
match args.cmd { | ||
Some(SubCommand::Update {}) => { | ||
// TODO(gib): Handle updates. | ||
update::update(config)?; | ||
} | ||
// TODO(gib): Handle multiple link directories both as args and in config. | ||
// TODO(gib): Add option to warn instead of failing if there are conflicts. | ||
// TODO(gib): Check for conflicts before doing any linking. | ||
Some(SubCommand::Link { | ||
from_dir, | ||
to_dir, | ||
backup_dir, | ||
}) => { | ||
link::link(&from_dir, &to_dir, &backup_dir)?; | ||
} | ||
None => { | ||
bail!("up requires a subcommand, use -h or --help for the usage args."); | ||
} | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.