Skip to content

Commit

Permalink
refactor(cli): merge query subcommand into search (#34)
Browse files Browse the repository at this point in the history
Moves the functionalities of the `nerdfix query` subcommand,
added in #33, into `nerdfix search`.
  • Loading branch information
loichyan authored Nov 23, 2024
1 parent 8663c33 commit 82adbf7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ are noticeable to end-users since the last release. For developers, this project

- Add a subcommand, `nerdfix completions <SHELL>`, to generate completions for your shell ([#30]).
- Support comments in JSON files ([#33]).
- Add a new `nerdfix query` subcommand, useful for querying icon infos from the database ([#33]).
- Add a new `codepoint:from/to` substitution type ([#33]).
- Support checking dropped icons of Nerd Fonts v3.3.0 through the newly added `nerdfix --nf-version=3.3.0` option
([#33], thanks [@Finii] and [@hasecilu]).
- Add two new options, `--codepoint` and `--name`, for `nerdfix search`, useful for querying icon infos from the
database non-interactively ([#??]).

[#30]: https://github.com/loichyan/nerdfix/pull/30
[#33]: https://github.com/loichyan/nerdfix/pull/33
Expand Down
13 changes: 8 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct Cli {
#[command(subcommand)]
pub cmd: Command,
/// [deprecated] Use `--input` instead.
#[arg(long, global = true, value_name = V_SUB)]
#[arg(long, global = true, value_name = V_PATH)]
pub substitution: Vec<IoPath>,
/// [deprecated] Use `--sub prefix:` instead.
#[arg(long, global = true, value_name = V_SUB)]
Expand Down Expand Up @@ -145,12 +145,15 @@ pub enum Command {
#[arg(value_name = V_SOURCE)]
source: Vec<IoPath>,
},
/// Fuzzy search for an icon.
Search {},
/// Query icon infos from the database, returned in JSON.
Query {
/// Query icon infos from the database.
///
/// If no argument is specified, it will open a prompt for interactive fuzzy
/// search.
Search {
/// Search for icon of the given codepoint, returned in JSON if matches.
#[arg(long, value_parser = crate::icon::parse_codepoint)]
codepoint: Option<char>,
/// Search for icon of the given name, returned in JSON if matches.
#[arg(long, conflicts_with = "codepoint")]
name: Option<String>,
},
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ fn main_impl() -> error::Result<()> {
.log_error();
}
}
Command::Search {} => {
rt.build().prompt_input_icon(None).ok();
}
Command::Query { codepoint, name } => {
Command::Search { codepoint, name } => {
let rt = rt.build();
let icon = if let Some(c) = codepoint {
rt.get_icon_by_codepoint(c)
} else if let Some(name) = name {
rt.get_icon_by_name(&name)
} else {
rt.prompt_input_icon(None).ok();
None
};
if let Some(icon) = icon {
Expand Down

0 comments on commit 82adbf7

Please sign in to comment.