-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plz): fully configurable plz menu
BREAKING CHANGE: this PR introduces a bunch of breaking changes to both the configuration system and the command-line interface. - Change the `plz` menu system to read the menu entries from the config file - Each entry contains its display string that will displayed in the menu and its operation/args - The `operation` is just a hash map that contains the operation key and its value and the rest of the arguments - Each operation has a specific set of pre-defined arguments that can be used to configure the `operation handler` and change its default behavior. - The operation handler will ignore any argument that doesn't know about - However, all the argument values will be passed to the template engine to be parsed before they are passed to the operation handler, which means that if there's any `template error` in any of the arguments the program will exit even if the argument that have the error doesn't needed by the operation handler - The currently available operations is: - `fetch` | `url`: fetch any page from the web(mainly) by HTTP - `run` | `command`: run command/s - `file`: just display the contents of any local file in the pager - Remove the following CLI options: - `--cheat-sh-url` - `--eg-url` - `--man-cmd` - `--cheat-url` - Introduce the following CLI options: - `-s` | `--selected-position`: used to set the default selected position, the posable values are: - `start`: The first item in the menu - `center`: The middle item in the menu (in case of an even number of items, the first item in the second half) - `end`: The last item in the menu COMMITS LIST: da8bb01 fix: un-use the wildcard pattern and use `as` instead (2 weeks ago) 0fdc42e chore(git): merge main and resolve confilcts (2 weeks ago) 9fd106d docs(readme): update the outdated examples (3 weeks ago) 446efff chore(config): just update the config file (3 weeks ago) a418fbd fix(test): fix the cli::update_config test and fi doc (3 weeks ago) 0187928 feat(file): create the file handler (3 weeks ago) a08101f feat(cli): add the --selected-position option to plz subcommand (3 weeks ago) 6d07d80 refactor: refactor and and lint and re-format the whole proj (3 weeks ago) 4dd0702 feat(command): create the command operation handler (3 weeks ago) 3eb71a6 refactor(plz): improve the operation handleing system (3 weeks ago) 3bb10a6 refactor: remove all the deprecate code and re-format the code (3 weeks ago) 9bfc239 revert(idea): remove the `.idea` directory (3 weeks ago) 1babee0 feat(plz): use the new system (3 weeks ago) f4d845e feat(cmd_parse): take a refrence to the hashmap (3 weeks ago) 0ed22dd feat(fetch): create the fetch handler and stabilize the `Handler` interface (3 weeks ago) 1646c14 feat(parser): cover more cases for the command parser (3 weeks ago) 5b054fb feat(parser): create the command parser (3 weeks ago) 399dfee feat(parser): create the template parser (3 weeks ago) ad409ab feat(plz): make the defualt selected item configrable (4 weeks ago) 218316a feat(plz): improve the cheat.sh url template (4 weeks ago) 08e7867 feat(plz): create the handler trait (4 weeks ago) bba0696 feat(plz): read the plz menu from the config file (4 weeks ago)
- Loading branch information
Showing
19 changed files
with
993 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
# configuration for https://github.com/orhun/halp | ||
|
||
# check the version flag | ||
check_version = true | ||
# check the help flag | ||
check_help = true | ||
# arguments to check | ||
check = [ [ "-v", "-V", "--version" ], [ "-h", "--help", "help", "-H" ] ] | ||
# command to run for manual pages | ||
check = [["-v", "-V", "--version", "version"], ["-h", "--help", "help", "-H"]] | ||
man_command = "man" | ||
# pager to use for command outputs | ||
pager_command = "less -R" | ||
# Cheat.sh URL | ||
cheat_sh_url = "https://cheat.sh" | ||
|
||
[plz_menu] | ||
selected_pos = "Center" | ||
|
||
[[plz_menu.entries]] | ||
display_msg = "Show man page" | ||
|
||
[plz_menu.entries.operation] | ||
run = "man {cmd}" | ||
|
||
[[plz_menu.entries]] | ||
display_msg = "Show cheat.sh page" | ||
|
||
[plz_menu.entries.operation] | ||
user-agent = "fetch" | ||
fetch = "https://cheat.sh/{cmd}{?/{subcommand}}{? {args}}" | ||
|
||
[[plz_menu.entries]] | ||
display_msg = "Show eg page" | ||
|
||
[plz_menu.entries.operation] | ||
fetch = "https://raw.githubusercontent.com/srsudar/eg/master/eg/examples/{cmd}.md" | ||
|
||
[[plz_menu.entries]] | ||
display_msg = "Show cheatsheets page" | ||
|
||
[plz_menu.entries.operation] | ||
fetch = "https://raw.githubusercontent.com/cheat/cheatsheets/master/{cmd}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use clap::ValueEnum; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
/// Default cheat sheet provider URL. | ||
const CHEAT_SH_URL_TEMPLATE: &str = "https://cheat.sh/{cmd}{?/{subcommand}}{? {args}}"; | ||
|
||
/// User agent for the cheat sheet provider. | ||
/// | ||
/// See <https://github.com/chubin/cheat.sh/blob/83bffa587b6c1048cbcc40ea8fa6af675203fd5f/bin/app.py#L76> | ||
const CHEAT_SH_USER_AGENT: &str = "fetch"; | ||
|
||
/// EG page provider URL. | ||
const EG_PAGES_URL_TEMPLATE: &str = | ||
"https://raw.githubusercontent.com/srsudar/eg/master/eg/examples/{cmd}.md"; | ||
|
||
/// The default cheatsheets provider URL. | ||
const CHEATSHEETS_URL_TEMPLATE: &str = | ||
"https://raw.githubusercontent.com/cheat/cheatsheets/master/{cmd}"; | ||
|
||
/// Plz menu config. | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct PlzMenu { | ||
/// The default selected poison in the menu. | ||
pub selected_pos: PlzMenuSelection, | ||
/// The menu entries. | ||
pub entries: Vec<PlzMenuEntry>, | ||
} | ||
|
||
/// Plz menu selection position. | ||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, ValueEnum)] | ||
pub enum PlzMenuSelection { | ||
/// The first item in the menu. | ||
Start, | ||
/// The middle item in the menu (in case of even number of items, the first item in the second half). | ||
Center, | ||
/// The last item in the menu. | ||
End, | ||
} | ||
|
||
/// Plz menu item. | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct PlzMenuEntry { | ||
/// The string to display in the menu. | ||
pub display_msg: String, | ||
/// The operation to perform. and its arguments. | ||
pub operation: HashMap<String, String>, | ||
} | ||
|
||
impl Default for PlzMenu { | ||
fn default() -> Self { | ||
PlzMenu { | ||
selected_pos: PlzMenuSelection::Center, | ||
entries: vec![ | ||
PlzMenuEntry { | ||
display_msg: "Show man page".to_string(), | ||
operation: HashMap::from([("run".to_string(), "man {cmd}".to_string())]), | ||
}, | ||
PlzMenuEntry { | ||
display_msg: "Show cheat.sh page".to_string(), | ||
operation: HashMap::from([ | ||
("fetch".to_string(), CHEAT_SH_URL_TEMPLATE.to_string()), | ||
("user-agent".to_string(), CHEAT_SH_USER_AGENT.to_string()), | ||
]), | ||
}, | ||
PlzMenuEntry { | ||
display_msg: "Show eg page".to_string(), | ||
operation: HashMap::from([( | ||
"fetch".to_string(), | ||
EG_PAGES_URL_TEMPLATE.to_string(), | ||
)]), | ||
}, | ||
PlzMenuEntry { | ||
display_msg: "Show cheatsheets page".to_string(), | ||
operation: HashMap::from([( | ||
"fetch".to_string(), | ||
CHEATSHEETS_URL_TEMPLATE.to_string(), | ||
)]), | ||
}, | ||
], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.