Skip to content

Commit 98ed3b5

Browse files
authored
feat!: rename implicit "mainnet" network to "ic" and define implicit "ic" environment (#278)
* remove --mainnet and --ic flags * remove DEFAULT_MAINNET_NETWORK_URL * global constants LOCAL & IC * add implicit ic environment * fix docs * adjust tests and other reference * changelog * changelog cont. * fmt * update CLAUDE.md * shorthand flag -n for --network * refresh cli-docs
1 parent 535f74d commit 98ed3b5

File tree

18 files changed

+152
-234
lines changed

18 files changed

+152
-234
lines changed

.claude/CLAUDE.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ Two network types in `crates/icp/src/network/`:
109109

110110
The network launcher is automatically downloaded on first use. For development/debugging, you can override with `ICP_CLI_NETWORK_LAUNCHER_PATH`.
111111

112-
##### Network Overrides
112+
##### Implicit Networks and Environments
113113

114-
- Users can override the "local" network definition in their `icp.yaml` to customize the local development environment
115-
- The "mainnet" network is protected and cannot be overridden to prevent production deployment accidents
116-
- If no "local" network is defined, a default managed network on `localhost:8000` is automatically added
114+
The CLI provides two implicit networks and environments that are always available:
115+
116+
- **`local` network**: A default managed network on `localhost:8000`. Users can override this in their `icp.yaml` to customize the local development environment (e.g., different port or connecting to an existing network).
117+
- **`ic` network**: The IC mainnet at `https://icp-api.io`. This network is **protected** and cannot be overridden to prevent accidental production deployment with incorrect settings.
118+
119+
Corresponding implicit environments are also provided:
120+
- **`local` environment**: Uses the `local` network with all project canisters. This is the default environment when none is specified.
121+
- **`ic` environment**: Uses the `ic` network with all project canisters.
122+
123+
These constants are defined in `crates/icp/src/prelude.rs` as `LOCAL` and `IC` and are used throughout the codebase.
117124

118125
#### Identity & Canister IDs
119126

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* feat: Show `name` in `canister status` command
44
* feat: `icp canister metadata <canister> <metadata section>` now fetches metadata sections from specified canisters
55
* fix: Validate explicit canister paths and throw an error if `canister.yaml` is not found
6+
* feat!: Rename the implicit "mainnet" network to "ic"
7+
* The corresponding environment "ic" is defined implicitly which can be overwritten by user configuration
8+
* The `--mainnet` and `--ic` flags are removed. Use `-n/--network ic`, `-e/--environment ic` instead.
69

710
# v0.1.0-beta.3
811

crates/icp-cli/src/commands/network/args.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::Args;
2-
use icp::{context::NetworkOrEnvironmentSelection, project::DEFAULT_LOCAL_NETWORK_NAME};
2+
use icp::{context::NetworkOrEnvironmentSelection, prelude::LOCAL};
33

44
#[derive(Args, Clone, Debug)]
55
pub(crate) struct NetworkOrEnvironmentArgs {
@@ -51,8 +51,6 @@ impl From<NetworkOrEnvironmentArgs> for Result<NetworkOrEnvironmentSelection, an
5151
}
5252

5353
// Precedence 4: Default to "local" network (lowest)
54-
Ok(NetworkOrEnvironmentSelection::Network(
55-
DEFAULT_LOCAL_NETWORK_NAME.to_string(),
56-
))
54+
Ok(NetworkOrEnvironmentSelection::Network(LOCAL.to_string()))
5755
}
5856
}

crates/icp-cli/src/options.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use clap::{ArgGroup, Args};
22
use icp::context::{EnvironmentSelection, NetworkSelection};
33
use icp::identity::IdentitySelection;
4-
use icp::project::{
5-
DEFAULT_LOCAL_ENVIRONMENT_NAME, DEFAULT_MAINNET_ENVIRONMENT_NAME, DEFAULT_MAINNET_NETWORK_NAME,
6-
};
4+
use icp::prelude::LOCAL;
75
use url::Url;
86

97
mod heading {
@@ -47,38 +45,17 @@ pub(crate) struct EnvironmentOpt {
4745
help_heading = heading::NETWORK_PARAMETERS,
4846
)]
4947
environment: Option<String>,
50-
51-
/// Shorthand for --environment=ic.
52-
#[arg(
53-
long,
54-
global(true),
55-
group = "environment-select",
56-
group = "network-select",
57-
help_heading = heading::NETWORK_PARAMETERS,
58-
)]
59-
ic: bool,
6048
}
6149

6250
impl EnvironmentOpt {
6351
#[allow(dead_code)]
6452
pub(crate) fn name(&self) -> &str {
65-
// Support --ic
66-
if self.ic {
67-
return DEFAULT_MAINNET_ENVIRONMENT_NAME;
68-
}
69-
70-
// Otherwise, default to `local`
71-
self.environment
72-
.as_deref()
73-
.unwrap_or(DEFAULT_LOCAL_ENVIRONMENT_NAME)
53+
self.environment.as_deref().unwrap_or(LOCAL)
7454
}
7555
}
7656

7757
impl From<EnvironmentOpt> for EnvironmentSelection {
7858
fn from(v: EnvironmentOpt) -> Self {
79-
if v.ic {
80-
return EnvironmentSelection::Named(DEFAULT_MAINNET_ENVIRONMENT_NAME.to_string());
81-
}
8259
match v.environment {
8360
Some(name) => EnvironmentSelection::Named(name),
8461
None => EnvironmentSelection::Default,
@@ -90,19 +67,12 @@ impl From<EnvironmentOpt> for EnvironmentSelection {
9067
#[clap(group(ArgGroup::new("network-select").multiple(false)))]
9168
pub(crate) struct NetworkOpt {
9269
/// Name of the network to target, conflicts with environment argument
93-
#[arg(long, env = "ICP_NETWORK", group = "network-select", help_heading = heading::NETWORK_PARAMETERS)]
70+
#[arg(long, short = 'n', env = "ICP_NETWORK", group = "network-select", help_heading = heading::NETWORK_PARAMETERS)]
9471
network: Option<String>,
95-
96-
/// Shorthand for --network=mainnet
97-
#[arg(long, group = "network-select", help_heading = heading::NETWORK_PARAMETERS)]
98-
mainnet: bool,
9972
}
10073

10174
impl From<NetworkOpt> for NetworkSelection {
10275
fn from(v: NetworkOpt) -> Self {
103-
if v.mainnet {
104-
return NetworkSelection::Named(DEFAULT_MAINNET_NETWORK_NAME.to_string());
105-
}
10676
match v.network {
10777
Some(network) => match Url::parse(&network) {
10878
Ok(url) => NetworkSelection::Url(url),

crates/icp-cli/tests/common/clients/icp_cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use candid::Principal;
2-
use icp::{prelude::*, project::DEFAULT_LOCAL_ENVIRONMENT_NAME};
2+
use icp::prelude::*;
33

44
use crate::common::TestContext;
55

@@ -18,7 +18,7 @@ impl<'a> Client<'a> {
1818
Self {
1919
ctx,
2020
current_dir,
21-
environment: environment.unwrap_or(DEFAULT_LOCAL_ENVIRONMENT_NAME.to_string()),
21+
environment: environment.unwrap_or(LOCAL.to_string()),
2222
}
2323
}
2424

crates/icp-cli/tests/cycles_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async fn cycles_mint_with_explicit_network() {
147147
}
148148

149149
#[tokio::test]
150-
async fn cycles_mint_with_mainnet() {
150+
async fn cycles_mint_on_ic() {
151151
let ctx = TestContext::new();
152152

153153
// Setup project
@@ -156,10 +156,10 @@ async fn cycles_mint_with_mainnet() {
156156
// Create identity
157157
clients::icp(&ctx, &project_dir, None).use_new_random_identity();
158158

159-
// Run mint command with explicit --mainnet flag
159+
// Run mint command with --network ic
160160
ctx.icp()
161161
.current_dir(&project_dir)
162-
.args(["cycles", "mint", "--icp", "1", "--mainnet"])
162+
.args(["cycles", "mint", "--icp", "1", "--network", "ic"])
163163
.assert()
164164
.stderr(contains(
165165
"Error: Insufficient funds: 1.00010000 ICP required, 0 ICP available.",

crates/icp-cli/tests/network_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,18 @@ async fn override_local_network_with_custom_port() {
515515
}
516516

517517
#[tokio::test]
518-
async fn cannot_override_mainnet() {
518+
async fn cannot_override_ic() {
519519
let ctx = TestContext::new();
520-
let project_dir = ctx.create_project_dir("override-mainnet");
520+
let project_dir = ctx.create_project_dir("override-ic");
521521

522-
// Attempt to override mainnet
522+
// Attempt to override ic
523523
write_string(
524524
&project_dir.join("icp.yaml"),
525525
indoc! {r#"
526526
networks:
527-
- name: mainnet
527+
- name: ic
528528
mode: connected
529-
url: http://fake-mainnet.local
529+
url: http://fake-ic.local
530530
"#},
531531
)
532532
.expect("failed to write project manifest");
@@ -537,7 +537,7 @@ async fn cannot_override_mainnet() {
537537
.args(["build"])
538538
.assert()
539539
.failure()
540-
.stderr(contains("`mainnet` is a reserved network name"));
540+
.stderr(contains("`ic` is a reserved network name"));
541541
}
542542

543543
#[tokio::test]

crates/icp-cli/tests/project_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn explicit_path_with_subdirectory() {
267267
}
268268

269269
#[test]
270-
fn redefine_mainnet_network_disallowed() {
270+
fn redefine_ic_network_disallowed() {
271271
let ctx = TestContext::new();
272272

273273
// Setup project
@@ -277,9 +277,9 @@ fn redefine_mainnet_network_disallowed() {
277277
&project_dir.join("icp.yaml"),
278278
r#"
279279
networks:
280-
- name: mainnet
280+
- name: ic
281281
mode: connected
282-
url: https://fake-mainnet.io
282+
url: https://fake-ic.io
283283
"#,
284284
)
285285
.expect("failed to write project manifest");
@@ -290,5 +290,5 @@ fn redefine_mainnet_network_disallowed() {
290290
.args(["project", "show"])
291291
.assert()
292292
.failure()
293-
.stderr(contains("`mainnet` is a reserved network name"));
293+
.stderr(contains("`ic` is a reserved network name"));
294294
}

crates/icp/src/context/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use crate::{
1010
identity::IdentitySelection,
1111
network::{Configuration as NetworkConfiguration, access::NetworkAccess},
1212
prelude::*,
13-
project::{
14-
DEFAULT_LOCAL_ENVIRONMENT_NAME, DEFAULT_MAINNET_NETWORK_NAME, DEFAULT_MAINNET_NETWORK_URL,
15-
},
1613
store_id::{IdMapping, LookupIdError},
1714
};
1815
use candid::Principal;
@@ -46,7 +43,7 @@ pub enum EnvironmentSelection {
4643
impl EnvironmentSelection {
4744
pub fn name(&self) -> &str {
4845
match self {
49-
EnvironmentSelection::Default => DEFAULT_LOCAL_ENVIRONMENT_NAME,
46+
EnvironmentSelection::Default => LOCAL,
5047
EnvironmentSelection::Named(name) => name,
5148
}
5249
}
@@ -160,12 +157,12 @@ impl Context {
160157
name: network_name.to_owned(),
161158
})?;
162159
Ok(net.clone())
163-
} else if network_name == DEFAULT_MAINNET_NETWORK_NAME {
160+
} else if network_name == IC {
164161
Ok(crate::Network {
165-
name: DEFAULT_MAINNET_NETWORK_NAME.to_string(),
162+
name: IC.to_string(),
166163
configuration: crate::network::Configuration::Connected {
167164
connected: crate::network::Connected {
168-
url: DEFAULT_MAINNET_NETWORK_URL.to_string(),
165+
url: IC_MAINNET_NETWORK_URL.to_string(),
169166
root_key: None,
170167
},
171168
},

0 commit comments

Comments
 (0)