-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Accept an environment as argument for network commands #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a085de5
feat: Accept an environment as argument for network commands
raymondk 1bc5fc9
update changelog
raymondk b1608c8
lint
raymondk 65d6fa3
move examples in after_long_help
raymondk 310e519
Merge branch 'main' into rk/network-environment-ctd
raymondk 8064005
cli ref
raymondk 79a38c4
lowercase it
raymondk 0d779e8
Merge branch 'main' into rk/network-environment-ctd
raymondk 7c7a995
Merge branch 'main' into rk/network-environment-ctd
raymondk 47787e6
fix
raymondk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
| use clap::Args; | ||
| use icp::{context::NetworkOrEnvironmentSelection, project::DEFAULT_LOCAL_NETWORK_NAME}; | ||
|
|
||
| #[derive(Args, Clone, Debug)] | ||
| pub(crate) struct NetworkOrEnvironmentArgs { | ||
| /// Name of the network to use | ||
| #[arg( | ||
| help = "Name of the network to use. Overrides ICP_ENVIRONMENT if set.", | ||
| long_help = "Name of the network to use.\n\n\ | ||
| Takes precedence over -e/--environment and the ICP_ENVIRONMENT \ | ||
| environment variable when specified explicitly." | ||
| )] | ||
| pub(crate) name: Option<String>, | ||
|
|
||
| /// Use the network from the specified environment | ||
| #[arg( | ||
| short = 'e', | ||
| long, | ||
| help = "Use the network from the specified environment", | ||
| long_help = "Use the network configured in the specified environment.\n\n\ | ||
| Cannot be used together with an explicit network name argument.\n\ | ||
| The ICP_ENVIRONMENT environment variable is also checked when \ | ||
| neither network name nor -e flag is specified." | ||
| )] | ||
| pub(crate) environment: Option<String>, | ||
| } | ||
|
|
||
| impl From<NetworkOrEnvironmentArgs> for Result<NetworkOrEnvironmentSelection, anyhow::Error> { | ||
| fn from(args: NetworkOrEnvironmentArgs) -> Self { | ||
| // Check for mutual exclusivity (both explicit) | ||
| if args.name.is_some() && args.environment.is_some() { | ||
| return Err(anyhow::anyhow!( | ||
| "Cannot specify both network name and environment. \ | ||
| Use either a network name or -e/--environment, not both." | ||
| )); | ||
| } | ||
|
|
||
| // Precedence 1: Explicit network name (highest) | ||
| if let Some(name) = args.name { | ||
| return Ok(NetworkOrEnvironmentSelection::Network(name)); | ||
| } | ||
|
|
||
| // Precedence 2: Explicit environment flag | ||
| if let Some(env_name) = args.environment { | ||
| return Ok(NetworkOrEnvironmentSelection::Environment(env_name)); | ||
| } | ||
|
|
||
| // Precedence 3: ICP_ENVIRONMENT variable | ||
| if let Ok(env_name) = std::env::var("ICP_ENVIRONMENT") { | ||
| return Ok(NetworkOrEnvironmentSelection::Environment(env_name)); | ||
| } | ||
|
|
||
| // Precedence 4: Default to "local" network (lowest) | ||
| Ok(NetworkOrEnvironmentSelection::Network( | ||
| DEFAULT_LOCAL_NETWORK_NAME.to_string(), | ||
| )) | ||
| } | ||
| } |
This file contains hidden or 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,5 +1,6 @@ | ||
| use clap::Subcommand; | ||
|
|
||
| mod args; | ||
| pub(crate) mod list; | ||
| pub(crate) mod ping; | ||
| pub(crate) mod start; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.