diff --git a/src/args.rs b/src/args.rs index ca9f734..1fb8e99 100644 --- a/src/args.rs +++ b/src/args.rs @@ -72,30 +72,11 @@ pub enum Commands { #[clap(alias("shot"), alias("screenshot"), alias("screenshots"))] Shots(ShotsCommands), - /// Set, get, and generate device name. - #[command(subcommand)] - Name(NameCommands), - /// Interact with catalog.fireflyzero.com. #[command(subcommand)] Catalog(CatalogCommands), } -#[derive(Subcommand, Debug)] -pub enum NameCommands { - /// Show the current device name. - #[clap(alias("show"), alias("echo"))] - Get, - - /// Set a new device name. - #[clap(alias("change"))] - Set(NameSetArgs), - - /// Set a new device name. - #[clap(alias("gen"), alias("new"))] - Generate, -} - #[derive(Subcommand, Debug)] pub enum CatalogCommands { /// List all games available in the catalog. diff --git a/src/cli.rs b/src/cli.rs index d587707..4d112c3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,11 +22,6 @@ pub fn run_command(vfs: PathBuf, command: &Commands) -> anyhow::Result<()> { CatalogCommands::List(args) => cmd_catalog_list(args), CatalogCommands::Show(args) => cmd_catalog_show(args), }, - Name(command) => match command { - NameCommands::Get => cmd_name_get(&vfs), - NameCommands::Set(args) => cmd_name_set(&vfs, args), - NameCommands::Generate => cmd_name_generate(&vfs), - }, Runtime(root_args) => match &root_args.command { RuntimeCommands::Launch(args) => cmd_launch(root_args, args), RuntimeCommands::Restart => cmd_restart(root_args), diff --git a/src/commands/mod.rs b/src/commands/mod.rs index ece4d12..2bffbfa 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,7 +9,6 @@ mod import; mod inspect; mod logs; mod monitor; -mod name; mod new; mod postinstall; mod repl; @@ -29,7 +28,6 @@ pub use import::cmd_import; pub use inspect::cmd_inspect; pub use logs::cmd_logs; pub use monitor::cmd_monitor; -pub use name::{cmd_name_generate, cmd_name_get, cmd_name_set}; pub use new::cmd_new; pub use postinstall::cmd_postinstall; pub use repl::cmd_repl; diff --git a/src/commands/name.rs b/src/commands/name.rs deleted file mode 100644 index 2dbb1ad..0000000 --- a/src/commands/name.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::args::NameSetArgs; -use crate::vfs::generate_valid_name; -use anyhow::{Context, Result, bail}; -use firefly_types::Encode; -use std::fs; -use std::path::Path; - -pub fn cmd_name_get(vfs: &Path) -> Result<()> { - let name_path = vfs.join("sys").join("name"); - let name = fs::read_to_string(name_path)?; - if let Err(err) = firefly_types::validate_id(&name) { - println!("⚠️ the name is not valid: {err}"); - } - println!("{name}"); - Ok(()) -} - -pub fn cmd_name_set(vfs: &Path, args: &NameSetArgs) -> Result<()> { - let name_path = vfs.join("sys").join("name"); - let old_name = fs::read_to_string(&name_path)?; - println!("old name: {old_name}"); - if let Err(err) = firefly_types::validate_id(&args.name) { - bail!("validate new name: {err}"); - } - write_name(vfs, &args.name)?; - println!("new name: {}", &args.name); - Ok(()) -} - -pub fn cmd_name_generate(vfs: &Path) -> Result<()> { - let name = generate_valid_name(); - write_name(vfs, &name)?; - println!("new name: {name}"); - Ok(()) -} - -fn write_name(vfs: &Path, name: &str) -> Result<()> { - let name_path = vfs.join("sys").join("name"); - fs::write(name_path, name)?; - let settings_path = vfs.join("sys").join("config"); - let raw = fs::read(&settings_path).context("read settings")?; - let mut settings = firefly_types::Settings::decode(&raw[..]).context("parse settings")?; - settings.name = name.to_string(); - let raw = settings.encode_vec().context("encode settings")?; - fs::write(settings_path, raw).context("write settings file")?; - Ok(()) -}