Skip to content

Commit f2d0a64

Browse files
author
Arthur Melton
committed
better arg getter
1 parent 9a8c760 commit f2d0a64

File tree

3 files changed

+109
-64
lines changed

3 files changed

+109
-64
lines changed

Cargo.lock

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ rustc-serialize = "0.3.24"
1818
openssl = { version = "0.10", features = ["vendored"] }
1919
sysinfo = "0.20.0"
2020
humantime = "2.1.0"
21+
clap = "2.33.3"
2122

src/main.rs

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
mod lexer;
22
mod run;
33

4-
use std::env;
54
use std::fs;
65
use std::fs::File;
76
use std::io::Write;
87
use std::process::Command;
98
extern crate pbr;
109
extern crate serde_json;
1110
use std::collections::HashMap;
11+
use clap::*;
1212

1313
use git2::Repository;
1414
use pbr::ProgressBar;
@@ -21,70 +21,51 @@ fn main() {
2121
run::error("Could not create dir.".to_string());
2222
}
2323
}
24-
let maybe_file = env::args().nth(1);
25-
let args = env::args();
26-
let mut dev = false;
27-
let mut compile = false;
28-
let mut hard = false;
29-
let mut run = false;
3024
let uses: Vec<String> = vec!["false".to_string(), "false".to_string()];
31-
for arg in args {
32-
if arg == "--dev" {
33-
dev = true;
34-
} else if arg == "--compile" {
35-
compile = true;
36-
} else if arg == "--hard" || arg == "-h" {
37-
hard = true;
38-
} else if arg == "run" {
39-
run = true;
40-
} else if arg == "--install" || arg == "-i" {
41-
if Path::new(".gitignore").exists() {
42-
let mut cont = fs::read_to_string(".gitignore").unwrap();
43-
cont.push_str("\n\n# Nyson\ndep");
44-
let _r = set_cont(".gitignore".to_string(), cont);
45-
} else {
46-
let r = set_cont(".gitignore".to_string(), "# Nyson\ndep".to_string());
47-
if r.is_err() {
48-
run::error("Could not set file contents.".to_string());
49-
}
50-
}
51-
make_path("".to_string());
52-
std::process::exit(1);
53-
} else if arg == "--init" {
54-
let r = set_cont("Nyson.json".to_string(), "{\n\t\"name\": \"My Program\",\n\t\"dep\": {\n\t\t\"Example\": \"https://github.com/Nyson-Programing-Language/example-dep.git\"\n\t}\n}".to_string());
55-
if r.is_err() {
56-
run::error("Could not set file contents.".to_string());
57-
}
58-
let r = fs::create_dir("src");
59-
if r.is_err() {
60-
run::error("Could not create dir.".to_string());
61-
}
62-
let r = set_cont(
63-
"src/main.nys".to_string(),
64-
"log(\"Hello World\");".to_string(),
65-
);
66-
if r.is_err() {
67-
run::error("Could not set file contents.".to_string());
68-
}
69-
std::process::exit(1);
70-
} else if arg == "--help" || arg == "-h" {
71-
println!(" HELP ");
72-
println!("-------------------------------------------------------------");
73-
println!("| --help - shows you help |");
74-
println!("| --dev - shows you some dev stuff so if you make a |");
75-
println!("| issue on github we will need you to do this |");
76-
println!("| --compile - compiles the code into a binary or exe |");
77-
println!("| --hard - (need -compile b4) but compiles with imp aka|");
78-
println!("| apps offline if you use a imp from the web |");
79-
println!("| --init - makes the init files |");
80-
println!("| --install - install all the dependencies |");
81-
println!("| run - runs the main.nys |");
82-
println!("-------------------------------------------------------------");
83-
std::process::exit(1);
84-
}
85-
}
86-
let file = if let Some(f) = maybe_file {
87-
f
25+
let matches = App::new("Nyson")
26+
.version("0.19")
27+
.about("a programing language made in rust")
28+
.arg(Arg::with_name("INPUT")
29+
.help("the file to run")
30+
.required(false)
31+
.index(1))
32+
.arg(Arg::with_name("dev")
33+
.short("d")
34+
.long("dev")
35+
.help("Gives you dev debug tools")
36+
.takes_value(false))
37+
.arg(Arg::with_name("compile")
38+
.short("c")
39+
.long("compile")
40+
.help("Compiles your program")
41+
.takes_value(false))
42+
.arg(Arg::with_name("hard")
43+
.short("h")
44+
.long("hard")
45+
.help("compiles the language to offline mode")
46+
.takes_value(false))
47+
.arg(Arg::with_name("run")
48+
.short("r")
49+
.long("run")
50+
.help("Runs the program")
51+
.takes_value(false))
52+
.arg(Arg::with_name("install")
53+
.short("i")
54+
.long("install")
55+
.help("installs all the dependencies")
56+
.takes_value(false))
57+
.arg(Arg::with_name("init")
58+
.long("init")
59+
.help("makes a new project")
60+
.takes_value(false))
61+
.get_matches();
62+
let mut compile = matches.is_present("compile");
63+
let mut hard = matches.is_present("hard");
64+
let mut run = matches.is_present("run");
65+
let mut dev = matches.is_present("dev");
66+
let mut file:String = String::new();
67+
if matches.is_present("INPUT") {
68+
file = matches.value_of("INPUT").unwrap().to_string();
8869
} else {
8970
loop {
9071
println!(">> (type quit to quit)");

0 commit comments

Comments
 (0)