Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/icp-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rand.workspace = true
reqwest.workspace = true
sec1.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
serde.workspace = true
snafu.workspace = true
thiserror.workspace = true
Expand Down
26 changes: 26 additions & 0 deletions crates/icp-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod deploy;
mod environment;
mod identity;
mod network;
mod project;
mod sync;
mod token;

Expand Down Expand Up @@ -68,14 +69,35 @@ pub struct Cmd {

#[derive(Subcommand, Debug)]
pub enum Subcmd {
/// Build a project
Build(build::Cmd),

/// Perform canister operations against a network
Canister(canister::Cmd),

/// Mint and manage cycles
Cycles(cycles::Cmd),

/// Deploy a project to an environment
Deploy(deploy::Cmd),

/// Show information about the current project environments
Environment(environment::Cmd),

/// Manage your identities
Identity(identity::IdentityCmd),

/// Launch and manage local test networks
Network(network::NetworkCmd),

/// Display information about the current project
#[clap(hide = true)] // TODO: figure out how to structure the commands later
Project(project::Cmd),

/// Synchronize canisters in the current environment
Sync(sync::Cmd),

/// Perform token transactions
Token(token::Cmd),
}

Expand All @@ -102,6 +124,9 @@ pub enum DispatchError {
#[snafu(transparent)]
Network { source: NetworkCommandError },

#[snafu(transparent)]
Project { source: project::CommandError },

#[snafu(transparent)]
Sync { source: sync::CommandError },

Expand All @@ -118,6 +143,7 @@ pub async fn dispatch(ctx: &Context, subcmd: Subcmd) -> Result<(), DispatchError
Subcmd::Environment(opts) => environment::exec(ctx, opts).await?,
Subcmd::Identity(opts) => identity::dispatch(ctx, opts).await?,
Subcmd::Network(opts) => network::dispatch(ctx, opts).await?,
Subcmd::Project(opts) => project::dispatch(ctx, opts).await?,
Subcmd::Sync(opts) => sync::exec(ctx, opts).await?,
Subcmd::Token(opts) => token::exec(ctx, opts).await?,
}
Expand Down
44 changes: 44 additions & 0 deletions crates/icp-cli/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use anyhow::Context as _;
use clap::{Parser, Subcommand};

use crate::commands::Context;

#[derive(Debug, Parser)]
pub struct Cmd {
#[command(subcommand)]
subcmd: ProjectSubcmd,
}

#[derive(Debug, Subcommand)]
pub enum ProjectSubcmd {
/// Outputs the project's effective yaml configuration.
Show(ShowCmd),
}

pub async fn dispatch(ctx: &Context, cmd: Cmd) -> Result<(), CommandError> {
match cmd.subcmd {
ProjectSubcmd::Show(subcmd) => show(ctx, subcmd).await?,
}
Ok(())
}

#[derive(Parser, Debug)]
pub struct ShowCmd;

#[derive(Debug, thiserror::Error)]
pub enum CommandError {
#[error(transparent)]
Unexpected(#[from] anyhow::Error),
}

/// Loads the project's configuration and output the effective yaml config
/// after resolving recipes
async fn show(ctx: &Context, _: ShowCmd) -> Result<(), CommandError> {
// Load the project manifest, which defines the canisters to be built.
let p = ctx.project.load().await.context("failed to load project")?;

let yaml = serde_yaml::to_string(&p).expect("Serializing to yaml failed");
println!("{yaml}");

Ok(())
}
24 changes: 4 additions & 20 deletions crates/icp-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, env::current_dir, sync::Arc};
use std::{env::current_dir, sync::Arc};

use anyhow::Error;
use clap::{CommandFactory, Parser};
Expand All @@ -7,16 +7,8 @@ use console::Term;
use icp::{
Directories, agent,
canister::{
self,
assets::Assets,
build::Builder,
prebuilt::Prebuilt,
recipe::{
self,
handlebars::{Handlebars, TEMPLATES},
},
script::Script,
sync::Syncer,
self, assets::Assets, build::Builder, prebuilt::Prebuilt, recipe::handlebars::Handlebars,
script::Script, sync::Syncer,
},
identity, manifest, network,
prelude::*,
Expand Down Expand Up @@ -135,19 +127,11 @@ async fn main() -> Result<(), Error> {
// Canister Artifact Store (wasm)
let artifacts = ArtifactStore::new(&cli.artifact_store);

// Handlebar Templates (for recipes)
let tmpls = TEMPLATES.map(|(name, tmpl)| (name.to_string(), tmpl.to_string()));

// Prepare http client
let http_client = reqwest::Client::new();

// Recipes
let recipe = Arc::new(recipe::Resolver {
handlebars: Arc::new(Handlebars {
recipes: HashMap::from_iter(tmpls),
http_client,
}),
});
let recipe = Arc::new(Handlebars { http_client });

// Project Manifest Locator
let mloc = Arc::new(manifest::Locator::new(
Expand Down
1 change: 1 addition & 0 deletions crates/icp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ic-ledger-types = { workspace = true }
ic-utils = { workspace = true }
icp-canister-interfaces = { workspace = true }
icrc-ledger-types = { workspace = true }
indoc = { workspace = true }
itertools = { workspace = true }
k256 = { workspace = true }
p256 = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/icp/src/canister/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt, sync::Arc};

use async_trait::async_trait;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::{Sender, error::SendError};

use crate::{
Expand All @@ -21,7 +21,7 @@ use crate::{
/// type: rust
/// package: my_canister
/// ```
#[derive(Clone, Debug, Deserialize, PartialEq, JsonSchema)]
#[derive(Clone, Debug, Deserialize, PartialEq, JsonSchema, Serialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum Step {
/// Represents a canister built using a custom script or command.
Expand Down Expand Up @@ -49,7 +49,7 @@ impl fmt::Display for Step {

/// Describes how the canister should be built into WebAssembly,
/// including the adapters and build steps responsible for the build.
#[derive(Clone, Debug, Deserialize, PartialEq, JsonSchema)]
#[derive(Clone, Debug, Deserialize, PartialEq, JsonSchema, Serialize)]
pub struct Steps {
pub steps: Vec<Step>,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/icp/src/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use anyhow::Context;
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::{LoadPath, fs::read, manifest::CanisterManifest, prelude::*};

Expand All @@ -15,7 +15,7 @@ pub mod script;
pub mod sync;

/// Canister settings, such as compute and memory allocation.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, JsonSchema)]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, JsonSchema, Serialize)]
pub struct Settings {
/// Compute allocation (0 to 100). Represents guaranteed compute capacity.
pub compute_allocation: Option<u64>,
Expand Down
Loading