Skip to content

Commit 85b35d8

Browse files
committed
Allow -X at later positions in the CLI
In particular, we now allow `-X` to _not_ be the first cli argument. This makes way for common options such as `--web-bundle` to be specified _before_ the `-X` flag.
1 parent f34b5c8 commit 85b35d8

2 files changed

Lines changed: 17 additions & 34 deletions

File tree

src/bin/tectonic/main.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::{env, process, str::FromStr};
66
use structopt::StructOpt;
77
use tectonic_status_base::plain::PlainStatusBackend;
88

9-
use structopt::clap;
109
use tectonic::{
1110
config::PersistentConfig,
1211
errors::SyncError,
@@ -40,15 +39,15 @@ mod v2cli {
4039
#[derive(Debug, StructOpt)]
4140
#[structopt(name = "Tectonic", about = "Process a (La)TeX document")]
4241
struct CliOptions {
43-
/// Use experimental V2 interface (see `tectonic -X --help`); must be the first argument
42+
/// Use experimental V2 interface (see `tectonic -X --help`)
4443
#[structopt(short = "X")]
4544
use_v2: bool,
4645

4746
/// How much chatter to print when running
4847
#[structopt(long = "chatter", short, name = "level", default_value = "default", possible_values(&["default", "minimal"]))]
4948
chatter_level: String,
5049

51-
/// Enable/disable colorful log output.
50+
/// Enable/disable colorful log output
5251
#[structopt(long = "color", name = "when", default_value = "auto", possible_values(&["always", "auto", "never"]))]
5352
cli_color: String,
5453

@@ -78,26 +77,34 @@ fn main() {
7877
unstable_opts::UnstableOptions::from_unstable_args(args.unstable.into_iter());
7978
}
8079

81-
// Migration to the "cargo-style" command-line interface. If the first
82-
// argument is `-X`, or argv[0] contains `nextonic`, we activate the
80+
// Migration to the "cargo-style" command-line interface. If the arguments
81+
// list contains `-X`, or argv[0] contains `nextonic`, we activate the
8382
// alternative operation mode. Once this experimental mode is working OK,
8483
// we'll start printing a message telling people to prefer the `-X` option
8584
// and use `-X compile` for the "classic" ("rustc"-style, current)
8685
// interface. After that's been in place for a while, we'll make V2 mode the
8786
// default.
8887

8988
let mut v2cli_enabled = false;
90-
let mut v2cli_arg_idx = 1;
89+
let mut v2cli_args = os_args[1..].to_vec(); // deep copy
9190

9291
if !os_args.is_empty() && os_args[0].to_str().map(|s| s.contains("nextonic")) == Some(true) {
9392
v2cli_enabled = true;
94-
} else if os_args.len() > 1 && os_args[1] == "-X" {
95-
v2cli_enabled = true;
96-
v2cli_arg_idx = 2;
93+
} else if let Some(index) = v2cli_args
94+
.to_vec()
95+
.iter()
96+
.position(|s| s.to_str().unwrap_or_default() == "-X")
97+
{
98+
// Try to parse as v1 cli first, and when that doesn't work,
99+
// interpret it as v2 cli:
100+
if CliOptions::from_args_safe().is_err() || CliOptions::from_args().use_v2 {
101+
v2cli_enabled = true;
102+
v2cli_args.remove(index);
103+
}
97104
}
98105

99106
if v2cli_enabled {
100-
v2cli::v2_main(&os_args[v2cli_arg_idx..]);
107+
v2cli::v2_main(&v2cli_args);
101108
return;
102109
}
103110

@@ -154,15 +161,6 @@ fn main() {
154161
Box::new(PlainStatusBackend::new(chatter_level)) as Box<dyn StatusBackend>
155162
};
156163

157-
if args.use_v2 {
158-
let err = clap::Error::with_description(
159-
"-X option must be the first argument if given",
160-
clap::ErrorKind::ArgumentConflict,
161-
);
162-
status.report_error(&err.into());
163-
process::exit(1)
164-
}
165-
166164
// Now that we've got colorized output, pass off to the inner function ...
167165
// all so that we can print out the word "error:" in red. This code
168166
// parallels various bits of the `error_chain` crate.

tests/executable.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -957,21 +957,6 @@ fn extra_search_paths() {
957957
error_or_panic(&output);
958958
}
959959

960-
/// -X in non-initial position fails
961-
#[test]
962-
fn bad_v2_position() {
963-
let output = run_tectonic(&PathBuf::from("."), &["-", "-X"]);
964-
error_or_panic(&output);
965-
}
966-
967-
#[cfg(feature = "serialization")]
968-
#[test]
969-
fn bad_v2_position_build() {
970-
let (_tempdir, temppath) = setup_v2();
971-
let output = run_tectonic(&temppath, &["build", "-X"]);
972-
error_or_panic(&output);
973-
}
974-
975960
/// Ensures that watch command succeeds, and when a file is changed while running it rebuilds
976961
/// periodically
977962
#[cfg(all(feature = "serialization", not(target_arch = "mips")))]

0 commit comments

Comments
 (0)