Skip to content

Commit 9ac2034

Browse files
author
HoolaBoola
committed
Reverted Clap back to functioning version, auto-completion scripts can now be generated.
1 parent 43df1a7 commit 9ac2034

5 files changed

Lines changed: 129 additions & 161 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ authors = ["HoolaBoola <jaime.heikkiladias@helsinki.fi>",
88
edition = "2018"
99
description = "Command line interface for TMC, written in Rust."
1010
license = "Apache-2.0"
11+
build = "build.rs"
1112

1213
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1314

1415
[dependencies]
1516
url = "2.2.1"
16-
clap = "3.0.0-beta.2"
17+
clap = "2.3.3"
1718
assert_cmd = "0.10"
1819
predicates = "1"
1920
anyhow = "1"
@@ -37,5 +38,4 @@ termcolor = "1.1"
3738
terminal_size = "0.1.16"
3839

3940
[build-dependencies]
40-
clap = "3.0.0-beta.2"
41-
clap_generate = "3.0.0-beta.2"
41+
clap = "2.3.3"

build.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use clap;
2-
//use clap_generate::{generate_to, generators::Zsh};
3-
use std::io::Error;
1+
use clap::Shell;
42

53
include!("src/cli.rs");
64

7-
fn main() -> Result<(), Error> {
8-
let _outdir = match std::env::var_os("OUT_DIR") {
9-
None => return Ok(()),
5+
fn main() {
6+
let outdir = match std::env::var_os("OUT_DIR") {
7+
None => {
8+
println!("Hellooo");
9+
return;
10+
}
1011
Some(outdir) => outdir,
1112
};
1213

13-
let mut _app = build_cli();
14-
//generate_to::<Zsh, _, _>(&mut app, "tmc", outdir);
14+
println!("{:?}", outdir);
1515

16-
Ok(())
16+
let mut app = build_cli();
17+
app.gen_completions("tmc", Shell::Zsh, outdir);
1718
}

src/cli.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,108 @@
1-
use clap::{App, AppSettings, Arg};
1+
use clap::{App, AppSettings, Arg, SubCommand};
22

33
const PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
44

5-
pub fn build_cli() -> App<'static> {
5+
pub fn build_cli() -> App<'static, 'static> {
66
App::new("Test My Code client written in Rust")
77
.setting(AppSettings::ArgRequiredElseHelp)
88
.version(PKG_VERSION.unwrap())
99
.about("Client for downloading, testing and submitting exercises through the Test My Code system")
10-
.subcommand(App::new("courses").about("List the available courses"))
10+
.subcommand(SubCommand::with_name("courses").about("List the available courses"))
1111
.subcommand(
12-
App::new("download")
12+
SubCommand::with_name("download")
1313
.about("Downloads course exercises")
1414
.arg(
15-
Arg::new("course")
16-
.short('c')
15+
Arg::with_name("course")
16+
.short("c")
1717
.long("course")
1818
.value_name("course name")
1919
.required(false),
2020
)
2121
.arg(
22-
Arg::new("currentdir")
23-
.short('d')
22+
Arg::with_name("currentdir")
23+
.short("d")
2424
.long("currentdir")
2525
.required(false),
2626
),
2727
)
2828
.subcommand(
29-
App::new("exercises")
29+
SubCommand::with_name("exercises")
3030
.about("List the exercises for a specific course")
31-
.arg(Arg::new("course").value_name("course").required(true)),
31+
.arg(Arg::with_name("course").value_name("course").required(true)),
3232
)
3333
.subcommand(
34-
App::new("login")
34+
SubCommand::with_name("login")
3535
.about("Login to TMC server")
3636
.arg(
37-
Arg::new("non-interactive")
38-
.short('n')
39-
.about("Initiates the non-interactive mode.")
37+
Arg::with_name("non-interactive")
38+
.short("n")
39+
.help("Initiates the non-interactive mode.")
4040
.long("non-interactive"),
4141
),
4242
)
43-
.subcommand(App::new("logout").about("Logout from TMC server"))
43+
.subcommand(SubCommand::with_name("logout").about("Logout from TMC server"))
4444
.subcommand(
45-
App::new("organization")
45+
SubCommand::with_name("organization")
4646
.about("Change organization")
4747
.arg(
48-
Arg::new("non-interactive")
49-
.short('n')
50-
.about("Initiates the non-interactive mode.")
48+
Arg::with_name("non-interactive")
49+
.short("n")
50+
.help("Initiates the non-interactive mode.")
5151
.long("non-interactive"),
5252
),
5353
)
5454
.subcommand(
55-
App::new("paste")
55+
SubCommand::with_name("paste")
5656
.about("Submit exercise to TMC pastebin")
5757
.arg(
58-
Arg::new("exercise")
58+
Arg::with_name("exercise")
5959
.value_name("exercise")
6060
.required(false),
6161
),
6262
)
6363
.subcommand(
64-
App::new("submit")
64+
SubCommand::with_name("submit")
6565
.about("Submit exercises to TMC server")
6666
.arg(
67-
Arg::new("exercise")
67+
Arg::with_name("exercise")
6868
.value_name("exercise")
6969
.required(false),
7070
),
7171
)
7272
.subcommand(
73-
App::new("test")
73+
SubCommand::with_name("test")
7474
.about("Run local exercise tests")
7575
.arg(
76-
Arg::new("exercise")
76+
Arg::with_name("exercise")
7777
.value_name("exercise")
7878
.required(false),
7979
),
8080
)
8181
.subcommand(
82-
App::new("fetchupdate")
82+
SubCommand::with_name("fetchupdate")
8383
.setting(AppSettings::Hidden)
8484
.about("Finishes the autoupdater. Administator rights needed."),
8585
)
8686
.subcommand(
87-
App::new("cleartemp")
87+
SubCommand::with_name("cleartemp")
8888
.setting(AppSettings::Hidden)
8989
.about("Removes tempfiles. Administator rights needed."),
9090
)
9191
.subcommand(
92-
App::new("elevateddownload")
92+
SubCommand::with_name("elevateddownload")
9393
.setting(AppSettings::Hidden)
9494
.about("Downloads course from the tempfile. Administator rights needed."),
9595
)
96-
.subcommand(App::new("update").about("Update exercises"))
96+
.subcommand(SubCommand::with_name("update").about("Update exercises"))
9797
.arg(
98-
Arg::new("no-update")
99-
.short('d')
98+
Arg::with_name("no-update")
99+
.short("d")
100100
.long("no-update")
101-
.about("Disable auto update temporarily"),
101+
.help("Disable auto update temporarily"),
102102
)
103103
.arg(
104-
Arg::new("testmode")
104+
Arg::with_name("testmode")
105105
.long("testmode")
106-
.about("Only for internal testing, disables server connection"),
106+
.help("Only for internal testing, disables server connection"),
107107
)
108108
}

0 commit comments

Comments
 (0)