Compare commits
	
		
			No commits in common. "11ccdb54c7b75ac25e7ee27fe276b013ba9e7be2" and "36df27f3e6df0f0ca0a7004f27e2f1e432beedba" have entirely different histories.
		
	
	
		
			11ccdb54c7
			...
			36df27f3e6
		
	
		
| @ -1,10 +1,11 @@ | |||||||
| use clap::{builder::PossibleValue, Arg, Command}; | use clap::{builder::PossibleValue, Arg, ArgMatches, Command}; | ||||||
| use detee_cli::general::cli_handler::{ | use clap_complete::{generate, Shell}; | ||||||
|     handle_account, handle_completion, handle_operators, handle_packagers, | use detee_cli::general::cli_handler::handle_operators; | ||||||
| }; |  | ||||||
| use detee_cli::sgx::cli_handler::handle_app; | use detee_cli::sgx::cli_handler::handle_app; | ||||||
| use detee_cli::snp::cli_handler::{handle_vm, handle_vm_nodes}; | use detee_cli::snp::cli_handler::{handle_vm, handle_vm_nodes}; | ||||||
| use detee_cli::*; | use detee_cli::*; | ||||||
|  | use std::error::Error; | ||||||
|  | use std::io; | ||||||
| 
 | 
 | ||||||
| const ABOUT: &str = r#"The DeTEE CLI allows you to manage and deploy applications and virtual machines.
 | const ABOUT: &str = r#"The DeTEE CLI allows you to manage and deploy applications and virtual machines.
 | ||||||
| All software runs within Trusted Execution Environments on a distributed network. | All software runs within Trusted Execution Environments on a distributed network. | ||||||
| @ -572,3 +573,54 @@ fn main() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | fn disable_help_for_all_subcommands(mut cmd: Command) -> Command { | ||||||
|  |     cmd = cmd.disable_help_subcommand(true); | ||||||
|  |     let subcommands: Vec<_> = cmd | ||||||
|  |         .get_subcommands_mut() | ||||||
|  |         .map(|sub| disable_help_for_all_subcommands(sub.clone())) | ||||||
|  |         .collect(); | ||||||
|  |     for sub in subcommands { | ||||||
|  |         cmd = cmd.subcommand(sub); | ||||||
|  |     } | ||||||
|  |     cmd | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn handle_completion(matches: &ArgMatches, cmd: Command) { | ||||||
|  |     let mut cmd = disable_help_for_all_subcommands(cmd); | ||||||
|  |     if let Some(shell) = matches.get_one::<String>("shell") { | ||||||
|  |         let shell: Shell = shell.parse().expect("Invalid shell type"); | ||||||
|  |         generate(shell, &mut cmd, "detee-cli", &mut io::stdout()); | ||||||
|  |         if shell.to_string() == "fish" { | ||||||
|  |             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm delete' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); | ||||||
|  |             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm update' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); | ||||||
|  |             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm inspect' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); | ||||||
|  |             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm ssh' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn handle_account(matches: &ArgMatches) { | ||||||
|  |     match matches.subcommand() { | ||||||
|  |         Some(("show", _)) => cli_print(Ok(config::Config::get_account_data())), | ||||||
|  |         Some(("sign", path_subcommand)) => { | ||||||
|  |             let path: String = path_subcommand.get_one::<String>("path").unwrap().clone(); | ||||||
|  |             config::Config::init_config().sign_file(&path); | ||||||
|  |         } | ||||||
|  |         Some(("ssh-pubkey-path", path_subcommand)) => { | ||||||
|  |             let path: String = path_subcommand.get_one::<String>("path").unwrap().clone(); | ||||||
|  |             config::Config::set_ssh_pubkey_path(&path); | ||||||
|  |         } | ||||||
|  |         Some(("brain-url", path_subcommand)) => { | ||||||
|  |             let url: String = path_subcommand.get_one::<String>("url").unwrap().clone(); | ||||||
|  |             config::Config::set_brain_url(&url); | ||||||
|  |         } | ||||||
|  |         _ => cli_print(Ok(config::Config::get_account_data())), | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn handle_packagers( | ||||||
|  |     _matches: &ArgMatches, | ||||||
|  | ) -> Result<Vec<crate::packagers::Packager>, Box<dyn Error>> { | ||||||
|  |     Ok(crate::packagers::get_packagers()) | ||||||
|  | } | ||||||
|  | |||||||
| @ -1,11 +1,6 @@ | |||||||
| use super::operators; | use super::operators; | ||||||
| use super::packagers; |  | ||||||
| use crate::{cli_print, config}; | use crate::{cli_print, config}; | ||||||
| use clap::ArgMatches; | use clap::ArgMatches; | ||||||
| use clap::Command; |  | ||||||
| use clap_complete::{generate, Shell}; |  | ||||||
| use std::error::Error; |  | ||||||
| use std::io; |  | ||||||
| 
 | 
 | ||||||
| pub fn handle_operators(matches: &ArgMatches) { | pub fn handle_operators(matches: &ArgMatches) { | ||||||
|     match matches.subcommand() { |     match matches.subcommand() { | ||||||
| @ -39,52 +34,3 @@ pub fn handle_operators(matches: &ArgMatches) { | |||||||
|         _ => println!("To get more information about operators, use: detee-cli operator --help"), |         _ => println!("To get more information about operators, use: detee-cli operator --help"), | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 |  | ||||||
| pub fn handle_packagers(_matches: &ArgMatches) -> Result<Vec<packagers::Packager>, Box<dyn Error>> { |  | ||||||
|     Ok(packagers::get_packagers()) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn handle_account(matches: &ArgMatches) { |  | ||||||
|     match matches.subcommand() { |  | ||||||
|         Some(("show", _)) => cli_print(Ok(config::Config::get_account_data())), |  | ||||||
|         Some(("sign", path_subcommand)) => { |  | ||||||
|             let path: String = path_subcommand.get_one::<String>("path").unwrap().clone(); |  | ||||||
|             config::Config::init_config().sign_file(&path); |  | ||||||
|         } |  | ||||||
|         Some(("ssh-pubkey-path", path_subcommand)) => { |  | ||||||
|             let path: String = path_subcommand.get_one::<String>("path").unwrap().clone(); |  | ||||||
|             config::Config::set_ssh_pubkey_path(&path); |  | ||||||
|         } |  | ||||||
|         Some(("brain-url", path_subcommand)) => { |  | ||||||
|             let url: String = path_subcommand.get_one::<String>("url").unwrap().clone(); |  | ||||||
|             config::Config::set_brain_url(&url); |  | ||||||
|         } |  | ||||||
|         _ => cli_print(Ok(config::Config::get_account_data())), |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| pub fn handle_completion(matches: &ArgMatches, cmd: Command) { |  | ||||||
|     let mut cmd = disable_help_for_all_subcommands(cmd); |  | ||||||
|     if let Some(shell) = matches.get_one::<String>("shell") { |  | ||||||
|         let shell: Shell = shell.parse().expect("Invalid shell type"); |  | ||||||
|         generate(shell, &mut cmd, "detee-cli", &mut io::stdout()); |  | ||||||
|         if shell.to_string() == "fish" { |  | ||||||
|             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm delete' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); |  | ||||||
|             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm update' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); |  | ||||||
|             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm inspect' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); |  | ||||||
|             println!("complete -c detee-cli -n '__fish_seen_subcommand_from vm ssh' -a '(cat ~/.detee/cli/vms/uuid_list)' -f"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn disable_help_for_all_subcommands(mut cmd: Command) -> Command { |  | ||||||
|     cmd = cmd.disable_help_subcommand(true); |  | ||||||
|     let subcommands: Vec<_> = cmd |  | ||||||
|         .get_subcommands_mut() |  | ||||||
|         .map(|sub| disable_help_for_all_subcommands(sub.clone())) |  | ||||||
|         .collect(); |  | ||||||
|     for sub in subcommands { |  | ||||||
|         cmd = cmd.subcommand(sub); |  | ||||||
|     } |  | ||||||
|     cmd |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -1,4 +1,3 @@ | |||||||
| pub mod cli_handler; | pub mod cli_handler; | ||||||
| pub mod operators; | pub mod operators; | ||||||
| pub mod packagers; |  | ||||||
| // pub mod grpc;
 | // pub mod grpc;
 | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ pub mod config; | |||||||
| pub mod constants; | pub mod constants; | ||||||
| pub mod general; | pub mod general; | ||||||
| pub mod name_generator; | pub mod name_generator; | ||||||
|  | pub mod packagers; | ||||||
| pub mod sgx; | pub mod sgx; | ||||||
| pub mod snp; | pub mod snp; | ||||||
| pub mod utils; | pub mod utils; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user