diff --git a/Cargo.lock b/Cargo.lock index 6e7e53da090b4250ca6351374ed81b060eec8c09..1a4fe5cfd3bfc134a7218d719709762f1b6444a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,14 +231,6 @@ name = "gcc" version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "getopts" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "glob" version = "0.2.11" @@ -269,7 +261,6 @@ dependencies = [ "calculate 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "err-derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "ion-ranges 0.1.0", @@ -893,7 +884,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" -"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" diff --git a/Cargo.toml b/Cargo.toml index 0573f9748a653aadcf316031c8e73dfa9feb179f..965994800c55efdc696b8ed7ddf1d5a7f206e12a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,6 @@ ion_sys = { path = "members/sys" } ion-ranges = { path = "members/ranges" } hashbrown = "0.1.2" itertools = "0.8" -getopts = "0.2" lexical = "2.0" [lib] diff --git a/examples/help.out b/examples/help.out index 8c830bf9641e55d534b69b1f1cbf5f9f80d29c48..247edcde7998134a66cecc3fe91c12410943fc38 100644 --- a/examples/help.out +++ b/examples/help.out @@ -8,15 +8,15 @@ DESCRIPTION Ion is a commandline shell created to be a faster and easier to use alternative to the currently available shells. It is not POSIX compliant. -Args: - Script arguments (@args). If the -c option is not specified, the first parameter - is taken as a filename to execute +OPTIONS: + -c <command> evaluates given commands instead of reading from the commandline. -Options: - -c, --command COMMAND - evaluates given commands instead of reading from the - commandline - -n, --no-execute do not execute any commands, just do syntax checking. - -h, --help print this help menu - -v, --version print the version + -n or --no-execute + do not execute any commands, just do syntax checking. + -v or --version + prints the version, platform and revision of ion then exits. + +ARGS: + <args>... Script arguments (@args). If the -c option is not specified, the first + parameter is taken as a filename to execute diff --git a/src/lib/shell/binary/mod.rs b/src/lib/shell/binary/mod.rs index 397c904553e6547611be6da292e278b2166b1f0c..d661c7c604b40e21682545c356756526d5b103cd 100644 --- a/src/lib/shell/binary/mod.rs +++ b/src/lib/shell/binary/mod.rs @@ -24,9 +24,18 @@ DESCRIPTION Ion is a commandline shell created to be a faster and easier to use alternative to the currently available shells. It is not POSIX compliant. -Args: - Script arguments (@args). If the -c option is not specified, the first parameter - is taken as a filename to execute"; +OPTIONS: + -c <command> evaluates given commands instead of reading from the commandline. + + -n or --no-execute + do not execute any commands, just do syntax checking. + + -v or --version + prints the version, platform and revision of ion then exits. + +ARGS: + <args>... Script arguments (@args). If the -c option is not specified, the first + parameter is taken as a filename to execute"; pub trait Binary { /// Parses and executes the arguments that were supplied to the shell. diff --git a/src/main.rs b/src/main.rs index 64bb135d6d02044bbad2c7ae93089f8ad5bfcbd2..139a98654620cc52059afd3e42fbbd187c757cc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ extern crate ion_sys as sys; -use getopts::Options; use ion_shell::{flags::NO_EXEC, Binary, JobControl, ShellBuilder, MAN_ION}; use smallvec::SmallVec; use std::{ alloc::System, env, io::{stdin, BufReader, Read}, + iter::FromIterator, }; #[global_allocator] @@ -22,46 +22,41 @@ fn main() { let mut shell = shell.as_binary(); - let args: Vec<String> = env::args().collect(); - - let mut opts = Options::new(); - opts.optopt( - "c", - "command", - "evaluates given commands instead of reading from the commandline", - "COMMAND", - ); - opts.optflag("n", "no-execute", "do not execute any commands, just do syntax checking."); - opts.optflag("h", "help", "print this help menu"); - opts.optflag("v", "version", "print the version"); - let matches = opts - .parse(&args[1..]) - .map_err(|e| { - eprintln!("Error: {}", e); - std::process::exit(64); - }) - .unwrap(); - - if matches.opt_present("h") { - println!("{}", opts.usage(MAN_ION)); - return; - } - - if matches.opt_present("v") { - println!("{}", ion_shell::version()); - return; + let mut command = None; + let mut args = env::args().skip(1); + let mut script_path = None; + while let Some(arg) = args.next() { + match arg.as_str() { + "-n" | "--no-execute" => { + shell.flags |= NO_EXEC; + } + "-c" => command = args.next(), + "-v" | "--version" => { + println!("{}", ion_shell::version()); + return; + } + "-h" | "--help" => { + println!("{}", MAN_ION); + return; + } + _ => { + script_path = Some(arg); + break; + } + } } - if matches.opt_present("n") { - shell.flags |= NO_EXEC; - } - - let command = matches.opt_str("c"); - let parameters = matches.free.into_iter().map(small::String::from).collect::<SmallVec<_>>(); - let script_path = parameters.get(0).cloned(); - if !parameters.is_empty() { - shell.variables.set("args", parameters); - } + shell.variables.set( + "args", + SmallVec::from_iter( + script_path + .clone() + .or(env::args().next()) + .into_iter() + .chain(args) + .map(|arg| arg.into()), + ), + ); let status = if let Some(command) = command { shell.execute_script(&command);