diff --git a/README.md b/README.md index 0511500..b088693 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ simple process 3. Puts it in the `subject` field instead of the old subject 4. Appends the old subject to the `aliases` array +### `list` +Lists the subject field of every resource in the db + ### `query` A simple command to get the response JSON to a query without `curl`. It pretty-prints the JSON. diff --git a/src/args_parser.rs b/src/args_parser.rs index 1ee9300..1e88b95 100644 --- a/src/args_parser.rs +++ b/src/args_parser.rs @@ -89,6 +89,8 @@ pub enum Command { #[command(flatten)] server_reload: ServerReloadOptions, }, + /// Lists all subjects in the database + List {}, /// Runs a single query against the database and returns the resource associated with the value Query { /// The resource to query for diff --git a/src/editor/commands.rs b/src/editor/commands.rs index 288bc74..74565a7 100644 --- a/src/editor/commands.rs +++ b/src/editor/commands.rs @@ -1,4 +1,5 @@ pub mod editor; pub mod fetch; pub mod init; +pub mod list; pub mod query; diff --git a/src/editor/commands/list.rs b/src/editor/commands/list.rs new file mode 100644 index 0000000..f3cdfcc --- /dev/null +++ b/src/editor/commands/list.rs @@ -0,0 +1,9 @@ +use crate::schema::resource_list::ResourceList; +use std::path::PathBuf; + +pub fn list(database_path: PathBuf) { + let resources = ResourceList::load(database_path).unwrap(); + for resource in resources.0 { + println!("{}", resource.subject) + } +} diff --git a/src/main.rs b/src/main.rs index 2433ba7..f91d145 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use crate::args_parser::Command; use crate::editor::commands::editor::editor; use crate::editor::commands::init::init; +use crate::editor::commands::list::list; use crate::editor::try_reload_server::reload; use clap::Parser; use editor::commands::fetch::fetch; @@ -67,5 +68,8 @@ fn main() { Command::Init { force } => { init(data_paths.database_path, force); } + Command::List {} => { + list(data_paths.database_path); + } } }