Skip to content

Commit 018de50

Browse files
author
LorenzoTettamanti
committed
[#94]: added enviroment support. added set-env and get-env command
1 parent e5ec1a2 commit 018de50

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

cli/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ edition = "2024"
66
[dependencies]
77
clap = { version = "4.5.38", features = ["derive"] }
88
tracing = "0.1.41"
9+
10+
#commented until first release
11+
12+
#[[bin]]
13+
#name="cfcli"
14+
#path="src/main.rs"

cli/src/essential.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
use crate::general::GeneralData;
2+
13
pub fn update_cli() {
24
println!("Updating CortexFlow CLI");
35
println!("Looking for a newer version");
46
}
5-
pub fn info() {}
7+
pub fn info(general_data: GeneralData) {
8+
println!("Version: {}", GeneralData::VERSION);
9+
println!("Author: {}", GeneralData::AUTHOR);
10+
println!("Description:{}", GeneralData::DESCRIPTION);
11+
println!("Environment: {}", general_data.get_env());
12+
}

cli/src/general.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
General details
3+
*/
4+
5+
pub struct GeneralData {
6+
env: String,
7+
}
8+
9+
impl GeneralData {
10+
pub const VERSION: &str = "0.1";
11+
pub const AUTHOR: &str = "CortexFlow";
12+
pub const DESCRIPTION: &str = "";
13+
14+
pub fn new(env: String) -> Self {
15+
GeneralData { env: env.to_string() }
16+
}
17+
pub fn set_env(mut self, env: String) {
18+
self.env = env;
19+
}
20+
pub fn get_env(self) -> String {
21+
self.env
22+
}
23+
pub fn get_env_output(self) {
24+
println!("{:?}", self.env)
25+
}
26+
}

cli/src/main.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,63 @@
11
mod essential;
22
mod install;
3+
mod general;
34

4-
use clap::{ Error, Parser, Subcommand };
5+
use clap::{ Error, Parser, Subcommand, Args };
56
use clap::command;
7+
use tracing::debug;
68

79
use crate::essential::{ info, update_cli };
810
use crate::install::install_cortexflow;
911

12+
use crate::general::GeneralData;
13+
1014
#[derive(Parser, Debug)]
11-
#[command(author = "CortexFlow", version = "0.1", about = None, long_about = None)]
12-
struct Args {
15+
#[command(
16+
author = GeneralData::AUTHOR,
17+
version = GeneralData::VERSION,
18+
about = None,
19+
long_about = None
20+
)]
21+
struct Cli {
1322
//name: String,
1423
#[clap(subcommand)]
1524
cmd: Option<Commands>,
25+
env: String,
1626
}
1727

1828
#[derive(Subcommand, Debug, Clone)]
1929
enum Commands {
2030
/* list of available commands */
31+
#[command(name="set-env")]
32+
SetEnv(SetArgs),
33+
#[command(name="get-env")]
34+
GetEnv,
35+
#[command(name="install")]
2136
Install,
37+
#[command(name="update")]
2238
Update,
39+
#[command(name="info")]
2340
Info,
2441
}
42+
#[derive(Args, Debug, Clone)]
43+
struct SetArgs {
44+
val: String,
45+
}
2546

2647
fn args_parser() -> Result<(), Error> {
27-
let args = Args::parse();
28-
println!("Arguments {:?}", args.cmd);
48+
let args = Cli::parse();
49+
let env = args.env;
50+
let general_data = GeneralData::new(env);
51+
debug!("Arguments {:?}", args.cmd);
2952
match args.cmd {
53+
Some(Commands::SetEnv(env)) => {
54+
general_data.set_env(env.val);
55+
Ok(())
56+
}
57+
Some(Commands::GetEnv) => {
58+
general_data.get_env_output();
59+
Ok(())
60+
}
3061
Some(Commands::Install) => {
3162
install_cortexflow();
3263
Ok(())
@@ -36,7 +67,7 @@ fn args_parser() -> Result<(), Error> {
3667
Ok(())
3768
}
3869
Some(Commands::Info) => {
39-
info();
70+
info(general_data);
4071
Ok(())
4172
}
4273
None => {

cli/src/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod essential;
22
pub mod install;
3+
pub mod general;

0 commit comments

Comments
 (0)