summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-07-16 22:54:34 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2022-07-16 22:54:34 -0400
commiteb8b155329b2c2689cc5b854f0b87f4448485c66 (patch)
tree594ec40cc8efc1176a5dcaac3a0d90ee5594433b
parent6d230ce96e668c168a5393ef3294623986d547fc (diff)
move --path option to default option
-rw-r--r--docs/command_arguments.md17
-rw-r--r--src/main.rs7
2 files changed, 21 insertions, 3 deletions
diff --git a/docs/command_arguments.md b/docs/command_arguments.md
new file mode 100644
index 0000000..21ec6a7
--- /dev/null
+++ b/docs/command_arguments.md
@@ -0,0 +1,17 @@
+# Command Line Arguments
+
+```
+usage: joshuto [options] [path]
+```
+ - `[path]`: tells joshuto to start in a specific directory
+
+Joshuto supports the following options from the command line:
+
+ - `-v` `--version`: outputs version of joshuto
+
+ - `-h` `--help`: shows help menu
+
+ - `--output-file <output-file>`: tells joshuto to output data to `<output-file>`.
+ - This is usually used so programs can know how to behave after joshuto exits.
+ - For example, cd into joshuto's current directory on quit
+
diff --git a/src/main.rs b/src/main.rs
index f7795a6..c1f47ab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -77,12 +77,12 @@ lazy_static! {
#[derive(Clone, Debug, StructOpt)]
pub struct Args {
- #[structopt(long = "path", parse(from_os_str))]
- path: Option<PathBuf>,
#[structopt(short = "v", long = "version")]
version: bool,
#[structopt(long = "output-file", parse(from_os_str))]
output_file: Option<PathBuf>,
+ #[structopt(name = "ARGUMENTS")]
+ rest: Vec<String>,
}
fn run_joshuto(args: Args) -> Result<i32, JoshutoError> {
@@ -91,7 +91,8 @@ fn run_joshuto(args: Args) -> Result<i32, JoshutoError> {
println!("{}-{}", PROGRAM_NAME, version);
return Ok(0);
}
- if let Some(p) = args.path.as_ref() {
+ if !args.rest.is_empty() {
+ let p = PathBuf::from(args.rest[0].as_str());
if let Err(e) = std::env::set_current_dir(p.as_path()) {
eprintln!("{}", e);
process::exit(1);