-
-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for --literal flag and literal entry in config #900
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7777bdb
add support for --literal flag and literal entry in config
PanGan21 c00bc07
update doc
PanGan21 7ef7c3d
add -N shorthand and align description with linum man page
PanGan21 78ddaf2
swap shoud_quote variable with literal
PanGan21 8472c1f
replace quote with literal in render function
PanGan21 ff7b194
fix conflicts
PanGan21 af4734f
revert Cargo.lock
PanGan21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,6 +1,8 @@ | ||
use crate::color::Colors; | ||
use crate::display; | ||
use crate::flags::{ColorOption, Display, Flags, HyperlinkOption, Layout, SortOrder, ThemeOption}; | ||
use crate::flags::{ | ||
ColorOption, Display, Flags, HyperlinkOption, Layout, Literal, SortOrder, ThemeOption, | ||
}; | ||
use crate::git::GitCache; | ||
use crate::icon::Icons; | ||
|
||
|
@@ -71,7 +73,7 @@ impl Core { | |
// or require a raw output (like the `wc` command). | ||
inner_flags.layout = Layout::OneLine; | ||
|
||
flags.should_quote = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed! |
||
flags.literal = Literal(true); | ||
}; | ||
|
||
let sorters = sort::assemble_sorters(&flags); | ||
|
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,85 @@ | ||
//! This module defines the [Literal]. To set it up from [Cli], a [Config] and its | ||
//! [Default] value, use its [configure_from](Configurable::configure_from) method. | ||
|
||
use super::Configurable; | ||
|
||
use crate::app::Cli; | ||
use crate::config_file::Config; | ||
|
||
/// The flag to set in order to show literal file names without quotes. | ||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)] | ||
pub struct Literal(pub bool); | ||
|
||
impl Configurable<Self> for Literal { | ||
/// Get a potential `Literal` value from [Cli]. | ||
/// | ||
/// If the "literal" argument is passed, this returns a `Literal` with value `true` in a | ||
/// [Some]. Otherwise this returns `Literal` with value `false` in a [Some]. | ||
fn from_cli(cli: &Cli) -> Option<Self> { | ||
if cli.literal { | ||
Some(Self(true)) | ||
} else { | ||
Some(Self(false)) | ||
} | ||
} | ||
|
||
/// Get a potential `Literal` value from a [Config]. | ||
/// | ||
/// If the `Config::indicators` has value, | ||
/// this returns its value as the value of the `Literal`, in a [Some]. | ||
/// Otherwise this returns `Literal` with value `false` in a [Some]. | ||
fn from_config(config: &Config) -> Option<Self> { | ||
if let Some(value) = config.literal { | ||
Some(Self(value)) | ||
} else { | ||
Some(Self(false)) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use clap::Parser; | ||
|
||
use super::Literal; | ||
|
||
use crate::app::Cli; | ||
use crate::config_file::Config; | ||
use crate::flags::Configurable; | ||
|
||
#[test] | ||
fn test_from_cli_none() { | ||
let argv = ["lsd"]; | ||
let cli = Cli::try_parse_from(argv).unwrap(); | ||
assert_eq!(Some(Literal(false)), Literal::from_cli(&cli)); | ||
} | ||
|
||
#[test] | ||
fn test_from_cli_literal() { | ||
let argv = ["lsd", "--literal"]; | ||
let cli = Cli::try_parse_from(argv).unwrap(); | ||
assert_eq!(Some(Literal(true)), Literal::from_cli(&cli)); | ||
} | ||
|
||
#[test] | ||
fn test_from_config_none() { | ||
assert_eq!( | ||
Some(Literal(false)), | ||
Literal::from_config(&Config::with_none()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_from_config_true() { | ||
let mut c = Config::with_none(); | ||
c.literal = Some(true); | ||
assert_eq!(Some(Literal(true)), Literal::from_config(&c)); | ||
} | ||
|
||
#[test] | ||
fn test_from_config_false() { | ||
let mut c = Config::with_none(); | ||
c.literal = Some(false); | ||
assert_eq!(Some(Literal(false)), Literal::from_config(&c)); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have gone to an already-released v1.0.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! actually, I was planning to use the GitHub auto-generate release note, this file may not be necessary, can you help create a PR to fix it and add a notice that we are no longer using this file, we use the GitHub auth-generate one instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly sure what you meant, but opened one here: #907
Let me know if it is what you meant.