-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: a lot of cleanup and rework with anyhow
Removed direct libc usage and using users crate instead Using anyhow crate everywhere so there is less messy code
- Loading branch information
Showing
24 changed files
with
873 additions
and
832 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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,19 +1,12 @@ | ||
use std::path::Path; | ||
|
||
use crate::config::ConfigFile; | ||
use crate::cli::cli_config::CmdConfigInspectArgs; | ||
use crate::ExitResult; | ||
|
||
pub fn inspect_config(cli_args: &CmdConfigInspectArgs) -> ExitResult { | ||
match ConfigFile::load_from_file(&cli_args.path) { | ||
Ok(x) => { | ||
println!("{:#?}", x); | ||
use crate::prelude::*; | ||
|
||
Ok(()) | ||
}, | ||
Err(err) => { | ||
// NOTE err is custom error so the message is already predefined | ||
eprintln!("{}", err); | ||
// TODO also try to find it as config name instead of literal path if prefixed @config | ||
pub fn inspect_config(cli_args: CmdConfigInspectArgs) -> Result<()> { | ||
println!("{:#?}", ConfigFile::load_from_file(Path::new(&cli_args.path))?); | ||
|
||
Err(1) | ||
} | ||
} | ||
Ok(()) | ||
} |
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
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,26 +1,28 @@ | ||
use crate::cli; | ||
use crate::util::{self, Engine}; | ||
use crate::ExitResult; | ||
use crate::prelude::*; | ||
|
||
pub fn container_exists(engine: Engine, mut cli_args: cli::CmdExistsArgs) -> ExitResult { | ||
pub fn container_exists(ctx: Context, mut cli_args: cli::CmdExistsArgs) -> Result<()> { | ||
// try to find container in current directory | ||
if cli_args.name.is_empty() { | ||
if let Some(containers) = util::find_containers_by_cwd(&engine) { | ||
// TODO this whole thing could be a function its used at least 3 times! | ||
if let Some(containers) = ctx.get_cwd_container() { | ||
if containers.is_empty() { | ||
eprintln!("Could not find a running container in current directory"); | ||
return Err(1); | ||
return Err(anyhow!("Could not find a running container in current directory")); | ||
} | ||
|
||
cli_args.name = containers.first().unwrap().clone(); | ||
} | ||
} | ||
|
||
match util::container_exists(&engine,&cli_args.name) { | ||
use std::process::exit; | ||
|
||
// TODO i am not sure if there is any problems with using exit here | ||
match ctx.engine_container_exists(&cli_args.name) { | ||
// give different exit code if the container exists but is not owned | ||
true => match util::get_container_ws(&engine, &cli_args.name) { | ||
true => match ctx.get_container_label(&cli_args.name, crate::CONTAINER_LABEL_CONTAINER_DIR) { | ||
Some(_) => Ok(()), | ||
None => Err(2), | ||
None => exit(2), | ||
}, | ||
false => Err(1), | ||
false => exit(1), | ||
} | ||
} |
Oops, something went wrong.