Add list subcommand

This commit is contained in:
Karcsesz 2024-02-15 00:03:06 +01:00
parent 8c03ac337d
commit 04a45720ca
5 changed files with 19 additions and 0 deletions

View file

@ -49,6 +49,9 @@ simple process
3. Puts it in the `subject` field instead of the old subject 3. Puts it in the `subject` field instead of the old subject
4. Appends the old subject to the `aliases` array 4. Appends the old subject to the `aliases` array
### `list`
Lists the subject field of every resource in the db
### `query` ### `query`
A simple command to get the response JSON to a query without `curl`. It pretty-prints the JSON. A simple command to get the response JSON to a query without `curl`. It pretty-prints the JSON.

View file

@ -89,6 +89,8 @@ pub enum Command {
#[command(flatten)] #[command(flatten)]
server_reload: ServerReloadOptions, 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 /// Runs a single query against the database and returns the resource associated with the value
Query { Query {
/// The resource to query for /// The resource to query for

View file

@ -1,4 +1,5 @@
pub mod editor; pub mod editor;
pub mod fetch; pub mod fetch;
pub mod init; pub mod init;
pub mod list;
pub mod query; pub mod query;

View file

@ -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)
}
}

View file

@ -1,6 +1,7 @@
use crate::args_parser::Command; use crate::args_parser::Command;
use crate::editor::commands::editor::editor; use crate::editor::commands::editor::editor;
use crate::editor::commands::init::init; use crate::editor::commands::init::init;
use crate::editor::commands::list::list;
use crate::editor::try_reload_server::reload; use crate::editor::try_reload_server::reload;
use clap::Parser; use clap::Parser;
use editor::commands::fetch::fetch; use editor::commands::fetch::fetch;
@ -67,5 +68,8 @@ fn main() {
Command::Init { force } => { Command::Init { force } => {
init(data_paths.database_path, force); init(data_paths.database_path, force);
} }
Command::List {} => {
list(data_paths.database_path);
}
} }
} }