Skip to content

Commit

Permalink
Better command structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipnir committed Jan 17, 2023
1 parent 32a6362 commit f736ba0
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.vscode
.idea
.elixir_ls
sdks/jvm/spawn-jvm/.idea
sdks/jvm/spawn-jvm/target

spawn-cli/target/

# The directory Mix will write compiled artifacts to.
/_build/
Expand Down
122 changes: 122 additions & 0 deletions spawn-cli/Cargo.lock

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

8 changes: 8 additions & 0 deletions spawn-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ name = "spawn-cli"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "spawn"
path = "src/main.rs"

[dependencies]
clap = { version = "4.1.1", features = ["derive"] }
anyhow = "1.0.68"
log = "0.4.0"
env_logger = "0.10"
tokio = { version = "1.24.1", features = ["macros", "rt-multi-thread"] }
10 changes: 10 additions & 0 deletions spawn-cli/src/api/apply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use clap::Parser;

use anyhow::Result;

#[derive(Parser, Debug)]
pub(crate) struct Args {}

pub(crate) async fn start(args: Args) -> Result<()> {
Ok(())
}
Empty file removed spawn-cli/src/api/commands.rs
Empty file.
10 changes: 10 additions & 0 deletions spawn-cli/src/api/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use clap::Parser;

use anyhow::Result;

#[derive(Parser, Debug)]
pub(crate) struct Args {}

pub(crate) async fn start(args: Args) -> Result<()> {
Ok(())
}
38 changes: 38 additions & 0 deletions spawn-cli/src/api/execution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::Result;
use clap::{Parser, Subcommand};

/// Spawn CLI
#[derive(Parser, Debug)]
#[command(version)]
pub struct Args {
#[command(subcommand)]
command: Commands,
}

#[derive(Debug, Subcommand)]
enum Commands {
/// Install Spawn Operator
///
Install(super::install::Args),

/// Create a Spawn project in different languages from template
///
Create(super::create::Args),

Apply(super::apply::Args),
}

pub(crate) async fn execute(augmented_args: Vec<String>) -> Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

let args = match Some(augmented_args) {
Some(arg) => Args::parse_from(arg),
None => Args::parse(),
};

match args.command {
Commands::Apply(arg) => super::apply::start(arg).await,
Commands::Create(arg) => super::create::start(arg).await,
Commands::Install(arg) => super::install::start(arg).await,
}
}
11 changes: 11 additions & 0 deletions spawn-cli/src/api/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use clap::Parser;

use anyhow::Result;

/// Spawn CLI
#[derive(Parser, Debug)]
pub(crate) struct Args {}

pub(crate) async fn start(args: Args) -> Result<()> {
Ok(())
}
6 changes: 5 additions & 1 deletion spawn-cli/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pub mod commands;
pub(crate) mod execution;

mod apply;
mod create;
mod install;
26 changes: 7 additions & 19 deletions spawn-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
mod api;

use clap::Parser;
use api::execution;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Name of the person to greet
#[arg(short, long)]
name: String,
use anyhow::Result;
use std::collections::VecDeque;

/// Number of times to greet
#[arg(short, long, default_value_t = 1)]
count: u8,
}

fn main() {
let args = Args::parse();

for _ in 0..args.count {
println!("Hello {}!", args.name)
}
#[tokio::main]
async fn main() -> Result<()> {
let augmented_args: VecDeque<String> = std::env::args().collect();
execution::execute(augmented_args.into()).await
}

0 comments on commit f736ba0

Please sign in to comment.