Rename -m / --markdown to -r / --raw

That flag name is clearer: We output raw page data without processing.
This commit is contained in:
Danilo Bargen 2021-10-17 20:53:12 +02:00
commit 8833b6b401
6 changed files with 23 additions and 9 deletions

View file

@ -6,7 +6,7 @@ _tealdeer()
_init_completion || return
case $prev in
-h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|-p|--pager|-m|--markdown|--show-paths|--seed-config|-q|--quiet)
-h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|-p|--pager|-r|--raw|--show-paths|--seed-config|-q|--quiet)
return
;;
-f|--render)

View file

@ -18,7 +18,7 @@ OPTIONS:
-u, --update Update the local cache
-c, --clear-cache Clear the local cache
-p, --pager Use a pager to page output
-m, --markdown Display the raw markdown instead of rendering it
-r, --raw Display the raw markdown instead of rendering it
-q, --quiet Suppress informational messages
--show-paths Show file and directory paths used by tealdeer
--config-path Show config file path

View file

@ -11,7 +11,7 @@ complete -c tldr -s o -l os -d 'Override the operating system.' -xa 'li
complete -c tldr -s u -l update -d 'Update the local cache.' -f
complete -c tldr -s c -l clear-cache -d 'Clear the local cache.' -f
complete -c tldr -s p -l pager -d 'Use a pager to page output.' -f
complete -c tldr -s m -l markdown -d 'Display the raw markdown instead of rendering it.' -f
complete -c tldr -s r -l raw -d 'Display the raw markdown instead of rendering it.' -f
complete -c tldr -s q -l quiet -d 'Suppress informational messages.' -f
complete -c tldr -l show-paths -d 'Show file and directory paths used by tealdeer.' -f
complete -c tldr -l seed-config -d 'Create a basic config.' -f

View file

@ -95,7 +95,11 @@ struct Args {
pager: bool,
/// Display the raw markdown instead of rendering it
#[clap(short = 'm', long = "markdown", requires = "command")]
#[clap(short = 'r', long = "--raw", requires = "command")]
raw: bool,
/// Deprecated alias of `raw`
#[clap(long = "markdown", short = 'm', requires = "command", hidden = true)]
markdown: bool,
/// Suppress informational messages
@ -363,7 +367,17 @@ fn main() {
init_log();
// Parse arguments
let args: Args = Args::parse();
let args = {
let mut args = Args::parse();
// Handle renamed arguments
if args.markdown {
args.raw = true;
eprintln!("Warning: The -m / --markdown flag is deprecated, use -r / --raw instead");
}
args
};
// Show config file and path, pass through
if args.config_path {
@ -425,7 +439,7 @@ fn main() {
// If a local file was passed in, render it and exit
if let Some(ref file) = args.render {
let path = PageLookupResult::with_page(PathBuf::from(file));
if let Err(msg) = print_page(&path, args.markdown, &config) {
if let Err(msg) = print_page(&path, args.raw, &config) {
eprintln!("{}", msg);
process::exit(1);
} else {
@ -484,7 +498,7 @@ fn main() {
&languages,
config.directories.custom_pages_dir.as_deref(),
) {
if let Err(msg) = print_page(&page, args.markdown, &config) {
if let Err(msg) = print_page(&page, args.raw, &config) {
eprintln!("{}", msg);
process::exit(1);
}

View file

@ -339,7 +339,7 @@ fn test_markdown_rendering() {
let expected = include_str!("which-markdown.expected");
testenv
.command()
.args(["-m", "which"])
.args(["--raw", "which"])
.assert()
.success()
.stdout(diff(expected));

View file

@ -24,7 +24,7 @@ _tealdeer() {
"($I -u --update)"{-u,--update}"[Update the local cache]"
"($I -c --clear-cache)"{-c,--clear-cache}"[Clear the local cache]"
"($I -p --pager)"{-p,--pager}"[Use a pager to page output]"
"($I -m --markdown)"{-m,--markdown}"[Display the raw markdown instead of rendering it]"
"($I -r --raw)"{-r,--raw}"[Display the raw markdown instead of rendering it]"
"($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]"
"($I)--show-paths[Show file and directory paths used by tealdeer]"
"($I)--seed-config[Create a basic config]"