Skip to content

Commit

Permalink
feat(storage-provider): Added a storage provider CLI component with d…
Browse files Browse the repository at this point in the history
…efined barebones and commands
  • Loading branch information
serg-temchenko committed May 29, 2024
1 parent ff1797b commit 3d4c76b
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 2 deletions.
36 changes: 35 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license-file = "LICENSE"
repository = "https://github.com/eigerco/polka-storage"

[workspace]
members = ["node", "primitives/cli", "runtime"]
members = ["cli/polka-storage-provider", "node", "primitives/cli", "runtime"]
resolver = "2"

# FIXME(#@jmg-duarte,#7,14/5/24): remove the patch once something >1.11.0 is released
Expand Down Expand Up @@ -39,6 +39,9 @@ smallvec = "1.11.0"
syn = { version = "2.0.53" }
thiserror = { version = "1.0.48" }
tracing-subscriber = { version = "0.3.18" }
url = "2.5.0"
env_logger = "0.11.2"
tokio = { version = "^1" }

# Local
polka-storage-runtime = { path = "runtime" }
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions cli/polka-storage-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "polka-storage-provider"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license-file.workspace = true
repository.workspace = true

[dependencies]
cli-primitives = { path = "../../primitives/cli" }
clap = { workspace = true, features = ["derive"] }
url = { workspace = true }
env_logger = { workspace = true }
tokio = { workspace = true, features = ["full"] }

[lints]
workspace = true
19 changes: 19 additions & 0 deletions cli/polka-storage-provider/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::commands::{RunRpcCmd, StopRpcCmd};
use clap::Parser;

/// A CLI application that facilitates management operations over a running full node and other components.
#[derive(Parser, Debug, Clone)]
#[command(author, version, about, long_about = None)]
pub(crate) struct Cli {
#[command(subcommand)]
pub subcommand: Option<Subcommand>,
}

/// Supported sub-commands.
#[derive(Debug, clap::Subcommand, Clone)]
pub enum Subcommand {
/// Command to run the RPC server.
RunRpc(RunRpcCmd),
/// Command to stop the RPC server.
StopRpc(StopRpcCmd),
}
7 changes: 7 additions & 0 deletions cli/polka-storage-provider/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod run_rpc_cmd;
mod stop_rpc_cmd;

pub(crate) mod runner;

pub(crate) use run_rpc_cmd::RunRpcCmd;
pub(crate) use stop_rpc_cmd::StopRpcCmd;
10 changes: 10 additions & 0 deletions cli/polka-storage-provider/src/commands/run_rpc_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use clap::Parser;
use url::Url;

/// The `run-rpc` command used to run a server to listen for RPC calls.
#[derive(Debug, Clone, Parser)]
pub(crate) struct RunRpcCmd {
/// RPC API endpoint of the parachain node.
#[arg(short = 'n', long, default_value = "ws://127.0.0.1:9944")]
pub node_rpc_address: Url,
}
26 changes: 26 additions & 0 deletions cli/polka-storage-provider/src/commands/runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::cli::Subcommand;
use crate::Cli;
use clap::Parser;
use cli_primitives::Result;

/// Parses command line arguments into the service configuration and runs the specified
/// command with it.
pub(crate) async fn run() -> Result<()> {
// CLI arguments parsed and mapped to the struct.
let cli_arguments: Cli = Cli::parse();

match &cli_arguments.subcommand {
Some(Subcommand::RunRpc(_cmd)) => {
// TODO(@serhii, #52, 2024-05-28): Implement an RPC server to listen for RPC calls, which will be used by the UI app to display information to the user.
Ok(())
}
Some(Subcommand::StopRpc(_cmd)) => {
// TODO(@serhii, #52, 2024-05-28): Implement functionality to gracefully stop the previously started RPC server.
Ok(())
}
None => {
// TODO(@serhii, #54, 2024-05-28): Add default logic for when no specific command is requested.
Ok(())
}
}
}
5 changes: 5 additions & 0 deletions cli/polka-storage-provider/src/commands/stop_rpc_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use clap::Parser;

/// The `stop-rpc` command used to stop a server that listen for RPC calls.
#[derive(Debug, Clone, Parser)]
pub(crate) struct StopRpcCmd {}
20 changes: 20 additions & 0 deletions cli/polka-storage-provider/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! A CLI application that facilitates management operations over a running full node and other components.
#![deny(unused_crate_dependencies)]

mod cli;

pub(crate) mod commands;
pub(crate) use cli::Cli;

use cli_primitives::Result;
use commands::runner;

#[tokio::main]
async fn main() -> Result<()> {
// Logger initialization.
env_logger::init();

// Run requested command.
runner::run().await
}

0 comments on commit 3d4c76b

Please sign in to comment.