2021-12-30 02:47:34 +00:00
|
|
|
pub mod config;
|
2021-12-29 16:49:24 +00:00
|
|
|
|
2021-12-30 03:38:04 +00:00
|
|
|
use ansi_term::Colour::Green;
|
|
|
|
use config::Config;
|
2021-12-29 13:15:19 +00:00
|
|
|
use std::error::Error;
|
2021-12-30 03:38:04 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2021-12-29 13:15:19 +00:00
|
|
|
|
2021-12-30 03:38:04 +00:00
|
|
|
pub fn run_add(paths: Vec<PathBuf>) -> Result<(), config::Error> {
|
|
|
|
debug_assert!(!paths.is_empty(), "`run_init` paths empty");
|
|
|
|
if paths.is_empty() {
|
|
|
|
return Err(config::Error::MissingConfig);
|
|
|
|
}
|
|
|
|
// TODO(jrpotter): Show $EDITOR that allows writing specific package.
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn run_init(paths: Vec<PathBuf>) -> Result<(), config::Error> {
|
|
|
|
// TODO(jrpotter): Use a nonempty implementation instead of this.
|
|
|
|
debug_assert!(!paths.is_empty(), "`run_init` paths empty");
|
|
|
|
if paths.is_empty() {
|
|
|
|
return Err(config::Error::MissingConfig);
|
|
|
|
}
|
2021-12-29 16:49:24 +00:00
|
|
|
// Check if we already have a local config somewhere. If so, reprompt the
|
|
|
|
// same configuration options and override the values present in the current
|
|
|
|
// YAML file.
|
2021-12-30 03:38:04 +00:00
|
|
|
match config::load(&paths) {
|
|
|
|
Ok((path, config)) => config::init(path, config),
|
|
|
|
// TODO(jrpotter): Verify I have permission to write at specified path.
|
|
|
|
// Make directories if necessary.
|
|
|
|
Err(config::Error::MissingConfig) => config::init(&paths[0], Config::default()),
|
|
|
|
Err(e) => Err(e),
|
2021-12-30 02:47:34 +00:00
|
|
|
}
|
2021-12-29 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 03:38:04 +00:00
|
|
|
pub fn run_list(paths: Vec<PathBuf>) -> Result<(), config::Error> {
|
|
|
|
debug_assert!(!paths.is_empty(), "`run_init` paths empty");
|
|
|
|
if paths.is_empty() {
|
|
|
|
return Err(config::Error::MissingConfig);
|
|
|
|
}
|
|
|
|
match config::load(&paths) {
|
|
|
|
Ok((path, config)) => {
|
|
|
|
// TODO(jrpotter): Should sort these entries.
|
|
|
|
// Also clean up where I use the console writing or not.
|
|
|
|
println!(
|
|
|
|
"Listing packages at {}...\n",
|
|
|
|
Green.paint(path.display().to_string())
|
|
|
|
);
|
|
|
|
for (k, _) in config.packages {
|
|
|
|
println!("• {}", k);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Err(e) => Err(e),
|
|
|
|
}
|
2021-12-29 13:15:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 03:38:04 +00:00
|
|
|
pub fn run_pull(_: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
2021-12-29 16:49:24 +00:00
|
|
|
Ok(())
|
2021-12-29 13:15:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 03:38:04 +00:00
|
|
|
pub fn run_push(_: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
2021-12-29 13:15:19 +00:00
|
|
|
Ok(())
|
|
|
|
}
|