2021-12-30 13:37:53 +00:00
|
|
|
pub mod cli;
|
2021-12-30 02:47:34 +00:00
|
|
|
pub mod config;
|
2021-12-30 13:37:53 +00:00
|
|
|
pub mod daemon;
|
2021-12-30 19:17:42 +00:00
|
|
|
pub mod path;
|
2021-12-29 16:49:24 +00:00
|
|
|
|
2021-12-30 13:37:53 +00:00
|
|
|
use config::PathConfig;
|
2021-12-30 19:17:42 +00:00
|
|
|
use path::NormalPathBuf;
|
2021-12-29 13:15:19 +00:00
|
|
|
use std::error::Error;
|
2021-12-30 19:17:42 +00:00
|
|
|
use std::io;
|
2021-12-29 13:15:19 +00:00
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_add(_config: PathConfig) -> Result<(), config::Error> {
|
2021-12-30 03:38:04 +00:00
|
|
|
// TODO(jrpotter): Show $EDITOR that allows writing specific package.
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_daemon(config: PathConfig) -> Result<(), Box<dyn Error>> {
|
|
|
|
daemon::launch(config)?;
|
2021-12-30 13:37:53 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_init(candidates: Vec<NormalPathBuf>) -> Result<(), config::Error> {
|
|
|
|
debug_assert!(!candidates.is_empty(), "Empty candidates found in `init`.");
|
|
|
|
if candidates.is_empty() {
|
|
|
|
return Err(config::Error::FileError(io::Error::new(
|
|
|
|
io::ErrorKind::NotFound,
|
|
|
|
"No suitable config file found.",
|
|
|
|
)));
|
|
|
|
}
|
2021-12-30 13:37:53 +00:00
|
|
|
match config::load(&candidates) {
|
|
|
|
// 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.
|
|
|
|
Ok(pending) => cli::write_config(pending),
|
|
|
|
// Otherwise create a new config file at the given location. We always
|
|
|
|
// assume we want to write to the first file in our priority list. If
|
|
|
|
// not, the user should specify which config they want to write using
|
|
|
|
// the `-c` flag.
|
2021-12-30 03:38:04 +00:00
|
|
|
// TODO(jrpotter): Verify I have permission to write at specified path.
|
|
|
|
// Make directories if necessary.
|
2021-12-30 13:37:53 +00:00
|
|
|
Err(config::Error::MissingConfig) if !candidates.is_empty() => {
|
|
|
|
let pending = PathConfig::new(&candidates[0], None);
|
|
|
|
cli::write_config(pending)
|
|
|
|
}
|
2021-12-30 03:38:04 +00:00
|
|
|
Err(e) => Err(e),
|
2021-12-30 02:47:34 +00:00
|
|
|
}
|
2021-12-29 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_list(config: PathConfig) -> Result<(), config::Error> {
|
|
|
|
cli::list_packages(config);
|
2021-12-30 13:37:53 +00:00
|
|
|
Ok(())
|
2021-12-29 13:15:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_pull(_config: PathConfig) -> Result<(), Box<dyn Error>> {
|
2021-12-29 16:49:24 +00:00
|
|
|
Ok(())
|
2021-12-29 13:15:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 19:17:42 +00:00
|
|
|
pub fn run_push(_config: PathConfig) -> Result<(), Box<dyn Error>> {
|
2021-12-29 13:15:19 +00:00
|
|
|
Ok(())
|
|
|
|
}
|