Skip to content

Commit

Permalink
feat(ark-cli): update parameters with default_value in clap
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jun 1, 2024
1 parent 5dd9c0d commit 8bd0480
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
11 changes: 9 additions & 2 deletions ark-cli/src/commands/file/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ pub struct Append {
id: String,
#[clap(help = "Content to append to the resource")]
content: String,
#[clap(short, long, value_enum, help = "Format of the resource")]
#[clap(
short,
long,
value_enum,
default_value = "raw",
help = "Format of the resource"
)]
format: Option<Format>,
#[clap(short, long, value_enum, help = "Storage kind of the resource")]
kind: Option<StorageType>,
Expand All @@ -35,12 +41,13 @@ impl Append {
translate_storage(&Some(self.root_dir.to_owned()), &self.storage)
.ok_or(AppError::StorageNotFound(self.storage.to_owned()))?;

// FIXME: Why do we have `self.kind` and `self.storage`? Both are used to determine the storage type
let storage_type = storage_type.unwrap_or(match self.kind {
Some(t) => t,
None => StorageType::File,
});

let format = self.format.unwrap_or(Format::Raw);
let format = self.format.unwrap();

let mut storage = Storage::new(file_path, storage_type)?;

Expand Down
3 changes: 0 additions & 3 deletions ark-cli/src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ impl List {
let no_tags = "NO_TAGS";
let no_scores = "NO_SCORE";

// FIXME: We should use a table library to print this.
// probably `comfy-table`

let longest_path = storage_entries
.iter()
.map(|entry| {
Expand Down
11 changes: 6 additions & 5 deletions ark-cli/src/commands/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use crate::{monitor_index, AppError};
pub struct Monitor {
#[clap(value_parser, help = "Path to the root directory")]
root_dir: Option<PathBuf>,
// FIXME: help message should specify what metric the interval is in
#[clap(help = "Interval to check for changes")]
#[clap(
default_value = "1000",
help = "Interval to check for changes in milliseconds"
)]
interval: Option<u64>,
}

impl Monitor {
pub fn run(&self) -> Result<(), AppError> {
// FIXME: 1000 should be the default value in clap configuration
// so users know
let millis = self.interval.unwrap_or(1000);
// SAFETY: interval is always Some since it has a default value in clap
let millis = self.interval.unwrap();
monitor_index(&self.root_dir, Some(millis))
}
}
7 changes: 4 additions & 3 deletions ark-cli/src/commands/storage/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ pub struct List {
root_dir: Option<PathBuf>,
#[clap(help = "Storage name")]
storage: Option<String>,
#[clap(short, long, help = "TODO: what is this flag for?")]
versions: Option<bool>,
// TODO: What is the purpose of this field? Add a help message to clarify.
#[clap(short, long, action = clap::ArgAction::SetTrue)]
versions: bool,
#[clap(short, long, value_enum, help = "Storage kind of the resource")]
kind: Option<StorageType>,
}
Expand All @@ -27,7 +28,7 @@ impl List {
"Storage was not provided".to_owned(),
))?;

let versions = self.versions.unwrap_or(false);
let versions = self.versions;

let (file_path, storage_type) =
translate_storage(&self.root_dir, storage)
Expand Down
2 changes: 2 additions & 0 deletions ark-cli/src/commands/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use clap::Subcommand;

mod list;

// FIXME: We should use new `fs-storage` crate to handle storage operations

/// Available commands for the `storage` subcommand
#[derive(Subcommand, Debug)]
pub enum Storage {
Expand Down

0 comments on commit 8bd0480

Please sign in to comment.