@@ -6,7 +6,6 @@ use std::{env, process, str::FromStr};
66use structopt:: StructOpt ;
77use tectonic_status_base:: plain:: PlainStatusBackend ;
88
9- use structopt:: clap;
109use 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" ) ]
4241struct 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.
0 commit comments