Skip to content

Commit 279ff54

Browse files
committed
Provide ValueHint to the command line options
1 parent 678ba63 commit 279ff54

6 files changed

Lines changed: 20 additions & 16 deletions

File tree

src/opt.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use anyhow::{Context, Error};
4-
use clap::Parser;
4+
use clap::{Parser, ValueHint};
55
use itertools::Itertools;
66

77
use task_maker_dag::DagPriority;
@@ -64,7 +64,7 @@ pub struct LoggerOpt {
6464
#[derive(Parser, Debug, Clone)]
6565
pub struct FindTaskOpt {
6666
/// Directory of the task
67-
#[clap(short = 't', long = "task-dir", default_value = "")]
67+
#[clap(short = 't', long = "task-dir", default_value = "", value_hint = ValueHint::DirPath)]
6868
pub task_dir: PathBuf,
6969

7070
/// Look at most for this number of parents for searching the task
@@ -117,7 +117,7 @@ pub struct ExecutionOpt {
117117
pub num_cores: Option<usize>,
118118

119119
/// Run the evaluation on a remote server instead of locally
120-
#[clap(long = "evaluate-on")]
120+
#[clap(long = "evaluate-on", value_hint = ValueHint::Url)]
121121
pub evaluate_on: Option<String>,
122122

123123
/// The name to use for the client in remote executions
@@ -133,7 +133,7 @@ pub struct ExecutionOpt {
133133
#[derive(Parser, Debug, Clone)]
134134
pub struct StorageOpt {
135135
/// Where to store the storage files, including the cache
136-
#[clap(long = "store-dir")]
136+
#[clap(long = "store-dir", value_hint = ValueHint::DirPath)]
137137
pub store_dir: Option<PathBuf>,
138138

139139
/// Maximum size of the storage directory, in MiB
@@ -151,12 +151,13 @@ pub struct FilterOpt {
151151
///
152152
/// Note that just the file name is checked (e.g. sol.cpp is the same as sol/sol.cpp). Without
153153
/// specifying anything all the solutions are executed.
154+
#[clap(value_hint = ValueHint::FilePath)]
154155
pub filter: Vec<String>,
155156

156157
/// Evaluate only the solution with the specified path
157158
///
158159
/// The solution can reside anywhere in the filesystem.
159-
#[clap(long, short)]
160+
#[clap(long, short, value_hint = ValueHint::FilePath)]
160161
pub solution: Vec<PathBuf>,
161162
}
162163

src/tools/booklet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::{Path, PathBuf};
22

33
use anyhow::{bail, Context, Error};
4-
use clap::Parser;
4+
use clap::{Parser, ValueHint};
55

66
use task_maker_format::ioi::{make_context_booklets, Booklet, BookletConfig, IOITask};
77
use task_maker_format::{find_task, EvaluationConfig};
@@ -18,13 +18,13 @@ pub struct BookletOpt {
1818
/// Directory of the context.
1919
///
2020
/// When specified, --task-dir should not be used.
21-
#[clap(short = 'c', long = "contest-dir")]
21+
#[clap(short = 'c', long = "contest-dir", value_hint = ValueHint::DirPath)]
2222
pub contest_dir: Option<PathBuf>,
2323

2424
/// Directory of the task.
2525
///
2626
/// When specified, --contest-dir should not be used.
27-
#[clap(short = 't', long = "task-dir")]
27+
#[clap(short = 't', long = "task-dir", value_hint = ValueHint::DirPath)]
2828
pub task_dir: Vec<PathBuf>,
2929

3030
/// Look at most for this number of parents for searching the task

src/tools/fuzz_checker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
44
use std::process::Stdio;
55

66
use anyhow::{anyhow, bail, Context, Error};
7-
use clap::Parser;
7+
use clap::{Parser, ValueHint};
88
use regex::Regex;
99
use serde::Deserialize;
1010

@@ -23,7 +23,7 @@ pub struct FuzzCheckerOpt {
2323
/// Where to store fuzzing data.
2424
///
2525
/// The path is relative to the task directory.
26-
#[clap(long, default_value = "fuzz")]
26+
#[clap(long, default_value = "fuzz", value_hint = ValueHint::DirPath)]
2727
pub fuzz_dir: PathBuf,
2828

2929
/// Additional sanitizers to use.

src/tools/gen_autocompletion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::fs::File;
44
use std::path::{Path, PathBuf};
55

66
use anyhow::{Context, Error};
7-
use clap::{Command, CommandFactory, Parser};
7+
use clap::{Command, CommandFactory, Parser, ValueHint};
88
use clap_complete::{Generator, Shell};
99

1010
#[derive(Parser, Debug)]
1111
pub struct GenAutocompletionOpt {
1212
/// Where to write the autocompletion files
13-
#[clap(short = 't', long = "target")]
13+
#[clap(short = 't', long = "target", value_hint = ValueHint::DirPath)]
1414
pub target: Option<PathBuf>,
1515
}
1616

src/tools/sandbox.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::Path;
33
use std::path::PathBuf;
44

55
use anyhow::{Context, Error};
6-
use clap::Parser;
6+
use clap::{Parser, ValueHint};
77
use tabox::configuration::SandboxConfiguration;
88
use tabox::syscall_filter::SyscallFilter;
99
use tabox::{Sandbox, SandboxImplementation};
@@ -14,11 +14,12 @@ use tempdir::TempDir;
1414
use task_maker_exec::sandbox::READABLE_DIRS;
1515

1616
#[derive(Parser, Debug, Clone)]
17+
#[clap(trailing_var_arg = true)]
1718
pub struct SandboxOpt {
1819
/// Working directory of the sandbox.
1920
///
2021
/// Will be mounted in /box inside the sandbox. Defaults to current working directory.
21-
#[clap(long, short)]
22+
#[clap(long, short, value_hint = ValueHint::DirPath)]
2223
pub workdir: Option<PathBuf>,
2324

2425
/// Memory limit for the sandbox, in KiB.
@@ -34,7 +35,7 @@ pub struct SandboxOpt {
3435
pub single_process: bool,
3536

3637
/// List of additional directory mounted read-only inside the sandbox.
37-
#[clap(long, short)]
38+
#[clap(long, short, value_hint = ValueHint::DirPath)]
3839
pub readable_dirs: Vec<PathBuf>,
3940

4041
/// Mount /tmp and /dev/null inside the sandbox
@@ -50,6 +51,7 @@ pub struct SandboxOpt {
5051
pub gid: usize,
5152

5253
/// Command to execute inside the sandbox. If not specified, bash is executed.
54+
#[clap(multiple_values = true, value_hint = ValueHint::CommandWithArguments)]
5355
pub command: Vec<String>,
5456
}
5557

src/tools/worker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use anyhow::{bail, Context, Error};
4-
use clap::Parser;
4+
use clap::{Parser, ValueHint};
55

66
use task_maker_exec::executors::{RemoteEntityMessage, RemoteEntityMessageResponse};
77
use task_maker_exec::Worker;
@@ -14,6 +14,7 @@ use crate::StorageOpt;
1414
#[derive(Parser, Debug, Clone)]
1515
pub struct WorkerOpt {
1616
/// Address to use to connect to a remote server
17+
#[clap(value_hint = ValueHint::Url)]
1718
pub server_addr: String,
1819

1920
/// ID of the worker (to differentiate between multiple workers on the same machine).

0 commit comments

Comments
 (0)