move import subcommand impl
This commit is contained in:
parent
37539f7679
commit
73281ef069
2 changed files with 22 additions and 20 deletions
|
@ -180,8 +180,8 @@ impl Manifest {
|
|||
.insert(account.account_name.clone(), Arc::new(Mutex::new(account)));
|
||||
}
|
||||
|
||||
pub fn import_account(&mut self, import_path: String) -> anyhow::Result<()> {
|
||||
let path = Path::new(&import_path);
|
||||
pub fn import_account(&mut self, import_path: &String) -> anyhow::Result<()> {
|
||||
let path = Path::new(import_path);
|
||||
ensure!(path.exists(), "{} does not exist.", import_path);
|
||||
ensure!(path.is_file(), "{} is not a file.", import_path);
|
||||
|
||||
|
@ -576,7 +576,7 @@ mod tests {
|
|||
let mut loaded_manifest = Manifest::new(manifest_path.as_path());
|
||||
assert!(matches!(
|
||||
loaded_manifest.import_account(
|
||||
tmp_dir
|
||||
&tmp_dir
|
||||
.path()
|
||||
.join("asdf1234.maFile")
|
||||
.into_os_string()
|
||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -229,7 +229,9 @@ fn run() -> anyhow::Result<()> {
|
|||
Some(cli::Subcommands::Setup(args)) => {
|
||||
return do_subcmd_setup(args, &mut manifest);
|
||||
},
|
||||
Some(cli::Subcommands::Import(args)) => {todo!()},
|
||||
Some(cli::Subcommands::Import(args)) => {
|
||||
return do_subcmd_import(args, &mut manifest);
|
||||
},
|
||||
Some(cli::Subcommands::Encrypt(args)) => {
|
||||
return do_subcmd_encrypt(args, &mut manifest);
|
||||
},
|
||||
|
@ -239,22 +241,6 @@ fn run() -> anyhow::Result<()> {
|
|||
_ => {},
|
||||
}
|
||||
|
||||
if let Some(import_matches) = matches.subcommand_matches("import") {
|
||||
for file_path in import_matches.values_of("files").unwrap() {
|
||||
match manifest.import_account(file_path.into()) {
|
||||
Ok(_) => {
|
||||
info!("Imported account: {}", file_path);
|
||||
}
|
||||
Err(err) => {
|
||||
bail!("Failed to import account: {} {}", file_path, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
manifest.save()?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut selected_accounts: Vec<Arc<Mutex<SteamGuardAccount>>>;
|
||||
loop {
|
||||
match get_selected_accounts(&matches, &mut manifest) {
|
||||
|
@ -682,6 +668,22 @@ fn do_subcmd_setup(args: cli::ArgsSetup, manifest: &mut accountmanager::Manifest
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
fn do_subcmd_import(args: cli::ArgsImport, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> {
|
||||
for file_path in args.files {
|
||||
match manifest.import_account(&file_path) {
|
||||
Ok(_) => {
|
||||
info!("Imported account: {}", &file_path);
|
||||
}
|
||||
Err(err) => {
|
||||
bail!("Failed to import account: {} {}", &file_path, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
manifest.save()?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn do_subcmd_encrypt(args: cli::ArgsEncrypt, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> {
|
||||
if !manifest.has_passkey() {
|
||||
let mut passkey;
|
||||
|
|
Loading…
Reference in a new issue