-
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.
WIP: probably the end of the refactor
All commands done just testing needed
- Loading branch information
Showing
9 changed files
with
104 additions
and
125 deletions.
There are no files selected for viewing
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), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! File containing constants | ||
|
||
/// Prefix env var name with proper prefix | ||
#[macro_export] | ||
macro_rules! ENV_VAR_PREFIX { | ||
($($args:literal),*) => { | ||
concat!(env!("CARGO_PKG_NAME_UPPERCASE"), "_", $($args),*) | ||
}; | ||
} | ||
|
||
pub const ENGINE_ERR_MSG: &str = "Failed to execute engine"; | ||
|
||
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
pub const FULL_VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "-", env!("VERGEN_GIT_DESCRIBE"), " (", env!("VERGEN_GIT_BRANCH"), ")"); | ||
|
||
pub const APP_NAME: &str = env!("CARGO_PKG_NAME"); | ||
pub const APP_NAME_UPPERCASE: &str = env!("CARGO_PKG_NAME_UPPERCASE"); | ||
|
||
/// Container label used to specify the host directory where container was started | ||
pub const CONTAINER_LABEL_HOST_DIR: &str = "host_dir"; | ||
|
||
/// Container label used to specify the path to main project in the container | ||
pub const CONTAINER_LABEL_CONTAINER_DIR: &str = "container_dir"; | ||
|
||
/// Wayland socket to pass through | ||
pub const ENV_WAYLAND_DISPLAY: &str = ENV_VAR_PREFIX!("WAYLAND_DISPLAY"); | ||
|
||
/// Container name | ||
pub const ENV_CONTAINER: &str = ENV_VAR_PREFIX!("CONTAINER"); | ||
|
||
/// Suffix added to each unnamed container created | ||
pub const ENV_CONTAINER_SUFFIX: &str = ENV_VAR_PREFIX!("CONTAINER_SUFFIX"); | ||
|
||
/// Image or config to use by default | ||
pub const ENV_IMAGE: &str = ENV_VAR_PREFIX!("IMAGE"); | ||
|
||
/// Directory where the app stores data | ||
pub const ENV_APP_DIR: &str = ENV_VAR_PREFIX!("DIR"); |