mirror of
https://github.com/qwjyh/xdbm
synced 2025-07-18 20:49:19 +09:00
redesign storage add Commands
- replace storage add args with subcommands of physical, directory, online - to make argument dependencies clearer
This commit is contained in:
parent
e3675632c1
commit
7c8ee7a500
8 changed files with 169 additions and 142 deletions
|
@ -15,10 +15,14 @@ use super::{local_info::LocalInfo, Storage, StorageExt, Storages};
|
|||
/// Subdirectory of other [Storage]s.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Directory {
|
||||
/// ID.
|
||||
name: String,
|
||||
/// ID of parent storage.
|
||||
parent: String,
|
||||
/// Relative path to the parent storage.
|
||||
relative_path: path::PathBuf,
|
||||
pub notes: String,
|
||||
/// Device and localinfo pairs.
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
|
@ -47,6 +51,7 @@ impl Directory {
|
|||
name: String,
|
||||
path: path::PathBuf,
|
||||
notes: String,
|
||||
alias: String,
|
||||
device: &devices::Device,
|
||||
storages: &Storages,
|
||||
) -> Result<Directory> {
|
||||
|
@ -69,7 +74,7 @@ impl Directory {
|
|||
})
|
||||
.context(format!("Failed to compare diff of paths"))?;
|
||||
trace!("Selected parent: {}", parent_name);
|
||||
let local_info = LocalInfo::new("".to_string(), path);
|
||||
let local_info = LocalInfo::new(alias, path);
|
||||
Ok(Directory::new(
|
||||
name,
|
||||
parent_name.clone(),
|
||||
|
|
|
@ -16,13 +16,19 @@ use super::{
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct OnlineStorage {
|
||||
/// ID.
|
||||
name: String,
|
||||
/// Provider string (for the common information).
|
||||
pub provider: String,
|
||||
/// Capacity in bytes.
|
||||
capacity: u64,
|
||||
/// Device and local info pairs.
|
||||
local_infos: HashMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
impl OnlineStorage {
|
||||
/// # Arguments
|
||||
/// - alias: for [`LocalInfo`]
|
||||
pub fn new(
|
||||
name: String,
|
||||
provider: String,
|
||||
|
|
|
@ -7,11 +7,8 @@ use anyhow::{anyhow, Context, Result};
|
|||
use byte_unit::Byte;
|
||||
use inquire::Text;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{self, PathBuf};
|
||||
use std::{
|
||||
collections::{hash_map::RandomState, HashMap},
|
||||
fmt,
|
||||
};
|
||||
use std::path;
|
||||
use std::{collections::HashMap, fmt};
|
||||
use sysinfo::{Disk, DiskExt, SystemExt};
|
||||
|
||||
use super::local_info::{self, LocalInfo};
|
||||
|
@ -191,8 +188,8 @@ impl fmt::Display for PhysicalDrivePartition {
|
|||
|
||||
/// Interactively select physical storage from available disks in sysinfo.
|
||||
pub fn select_physical_storage(
|
||||
disk_name: String,
|
||||
device: Device,
|
||||
storages: &Storages,
|
||||
) -> Result<PhysicalDrivePartition> {
|
||||
trace!("select_physical_storage");
|
||||
// get disk info fron sysinfo
|
||||
|
@ -206,22 +203,11 @@ pub fn select_physical_storage(
|
|||
trace!("{:?}", disk)
|
||||
}
|
||||
let disk = select_sysinfo_disk(&sys_disks)?;
|
||||
// name the disk
|
||||
let mut disk_name = String::new();
|
||||
trace!("{}", disk_name);
|
||||
loop {
|
||||
disk_name = Text::new("Name for the disk:").prompt()?;
|
||||
if storages.list.iter().all(|(k, v)| k != &disk_name) {
|
||||
break;
|
||||
}
|
||||
println!("The name {} is already used.", disk_name);
|
||||
}
|
||||
trace!("selected name: {}", disk_name);
|
||||
let storage = PhysicalDrivePartition::try_from_sysinfo_disk(&disk, disk_name, device)?;
|
||||
Ok(storage)
|
||||
}
|
||||
|
||||
pub fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
|
||||
fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
|
||||
let available_disks = sysinfo
|
||||
.disks()
|
||||
.iter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue