summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2023-08-13 21:34:42 -0700
committerWilfred Hughes <me@wilfred.me.uk>2023-08-13 21:34:42 -0700
commiteeb29749671dc73ae0196a8fcf4a29e17064e57f (patch)
treed50029a7857c0c6cfbcfc5813431615e74c6ec1a
parent1c60f3efd3cb9ab0c21a2d55a94834749cdf109c (diff)
Move option parsing before argument parsing
This is useful for additional mode parsing that wants to access these options.
-rw-r--r--src/options.rs112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/options.rs b/src/options.rs
index 202919e51..74982a59e 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -506,54 +506,6 @@ pub fn parse_args() -> Mode {
let args: Vec<_> = matches.values_of_os("paths").unwrap_or_default().collect();
info!("CLI arguments: {:?}", args);
- // TODO: document these different ways of calling difftastic.
- let (display_path, lhs_path, rhs_path, old_path, in_vcs) = match &args[..] {
- [lhs_path, rhs_path] => {
- let lhs_arg = FileArgument::from_cli_argument(lhs_path);
- let rhs_arg = FileArgument::from_cli_argument(rhs_path);
- let display_path = build_display_path(&lhs_arg, &rhs_arg);
- (display_path, lhs_arg, rhs_arg, None, false)
- }
- [display_path, lhs_tmp_file, _lhs_hash, _lhs_mode, rhs_tmp_file, _rhs_hash, _rhs_mode] => {
- // https://git-scm.com/docs/git#Documentation/git.txt-codeGITEXTERNALDIFFcode
- (
- display_path.to_string_lossy().to_string(),
- FileArgument::from_path_argument(lhs_tmp_file),
- FileArgument::from_path_argument(rhs_tmp_file),
- None,
- true,
- )
- }
- [old_name, lhs_tmp_file, _lhs_hash, _lhs_mode, rhs_tmp_file, _rhs_hash, _rhs_mode, new_name, _similarity] =>
- {
- // Rename file.
- // TODO: where does git document these 9 arguments?
-
- let old_name = old_name.to_string_lossy().to_string();
- let new_name = new_name.to_string_lossy().to_string();
-
- (
- new_name,
- FileArgument::from_path_argument(lhs_tmp_file),
- FileArgument::from_path_argument(rhs_tmp_file),
- Some(old_name),
- true,
- )
- }
- _ => {
- if !args.is_empty() {
- eprintln!(
- "error: Difftastic does not support being called with {} argument{}.\n",
- args.len(),
- if args.len() == 1 { "" } else { "s" }
- );
- }
- eprintln!("USAGE:\n\n {}\n", USAGE);
- eprintln!("For more information try --help");
- std::process::exit(EXIT_BAD_ARGUMENTS);
- }
- };
-
let display_width = if let Some(arg_width) = matches.value_of("width") {
arg_width
.parse::<usize>()
@@ -618,6 +570,62 @@ pub fn parse_args() -> Mode {
let check_only = matches.is_present("check-only");
+ let diff_options = DiffOptions {
+ graph_limit,
+ byte_limit,
+ parse_error_limit,
+ check_only,
+ ignore_comments,
+ };
+
+ // TODO: document these different ways of calling difftastic.
+ let (display_path, lhs_path, rhs_path, old_path, in_vcs) = match &args[..] {
+ [lhs_path, rhs_path] => {
+ let lhs_arg = FileArgument::from_cli_argument(lhs_path);
+ let rhs_arg = FileArgument::from_cli_argument(rhs_path);
+ let display_path = build_display_path(&lhs_arg, &rhs_arg);
+ (display_path, lhs_arg, rhs_arg, None, false)
+ }
+ [display_path, lhs_tmp_file, _lhs_hash, _lhs_mode, rhs_tmp_file, _rhs_hash, _rhs_mode] => {
+ // https://git-scm.com/docs/git#Documentation/git.txt-codeGITEXTERNALDIFFcode
+ (
+ display_path.to_string_lossy().to_string(),
+ FileArgument::from_path_argument(lhs_tmp_file),
+ FileArgument::from_path_argument(rhs_tmp_file),
+ None,
+ true,
+ )
+ }
+ [old_name, lhs_tmp_file, _lhs_hash, _lhs_mode, rhs_tmp_file, _rhs_hash, _rhs_mode, new_name, _similarity] =>
+ {
+ // Rename file.
+ // TODO: where does git document these 9 arguments?
+
+ let old_name = old_name.to_string_lossy().to_string();
+ let new_name = new_name.to_string_lossy().to_string();
+
+ (
+ new_name,
+ FileArgument::from_path_argument(lhs_tmp_file),
+ FileArgument::from_path_argument(rhs_tmp_file),
+ Some(old_name),
+ true,
+ )
+ }
+ _ => {
+ if !args.is_empty() {
+ eprintln!(
+ "error: Difftastic does not support being called with {} argument{}.\n",
+ args.len(),
+ if args.len() == 1 { "" } else { "s" }
+ );
+ }
+ eprintln!("USAGE:\n\n {}\n", USAGE);
+ eprintln!("For more information try --help");
+ std::process::exit(EXIT_BAD_ARGUMENTS);
+ }
+ };
+
let display_options = DisplayOptions {
background_color,
use_color,
@@ -630,14 +638,6 @@ pub fn parse_args() -> Mode {
in_vcs,
};
- let diff_options = DiffOptions {
- graph_limit,
- byte_limit,
- parse_error_limit,
- check_only,
- ignore_comments,
- };
-
Mode::Diff {
diff_options,
display_options,