Skip to content

Commit 49048b0

Browse files
author
Ionizing
committed
[clap] fix issues related to value_parser
1 parent 52f1320 commit 49048b0

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/commands/dos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct Dos {
204204
/// Render the plot and print the rendered code to stdout.
205205
to_inline_html: bool,
206206

207-
#[arg(long, default_value = "200")]
207+
#[arg(long, default_value_t = 200)]
208208
/// Sample density of DOS. Defined by number of points in 1 eV.
209209
sample_density: usize,
210210
}

src/commands/tdm.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ pub struct Tdm {
4747
/// processing WAVECAR produced by `vasp_gam`.
4848
gamma_half: Option<String>,
4949

50-
#[arg(short = 's', long, default_value = "1", value_parser = ["1", "2"])]
50+
#[arg(short = 's', long, default_value = "1", value_parser = clap::value_parser!(u64).range(1..=2))]
5151
/// Spin index, 1 for up, 2 for down.
52-
ispin: usize,
52+
ispin: u64,
5353

54-
#[arg(short = 'k', long, default_value = "1")]
54+
#[arg(short = 'k', long, default_value_t = 1)]
5555
/// K-point index, starts from 1.
5656
ikpoint: usize,
5757

@@ -63,7 +63,7 @@ pub struct Tdm {
6363
/// Final band indices, starts from 1.
6464
jbands: Vec<usize>,
6565

66-
#[arg(long, default_value = "0.05")]
66+
#[arg(long, default_value_t = 0.05)]
6767
/// Smearing width, in eV.
6868
sigma: f64,
6969

@@ -91,11 +91,11 @@ pub struct Tdm {
9191
/// Open the default browser to show the plot.
9292
show: bool,
9393

94-
#[arg(long, default_value = "0.1")]
94+
#[arg(long, default_value_t = 0.1)]
9595
/// Specify the width of bars in the center of peaks. (eV)
9696
barwidth: f64,
9797

98-
#[arg(long, default_value = "500")]
98+
#[arg(long, default_value_t = 500)]
9999
/// How many points in the x axis PER eV
100100
npoints: usize,
101101

@@ -211,11 +211,11 @@ I suggest you provide `gamma_half` argument to avoid confusion.");
211211
}
212212

213213

214-
let ispin = if self.ispin > 0 && self.ispin <= wav.nspin as usize {
214+
let ispin = if self.ispin > 0 && self.ispin <= wav.nspin {
215215
self.ispin - 1
216216
} else {
217217
bail!("Invalid ispin: ispin shoule be >= 1 and <= {}.", wav.nspin);
218-
};
218+
} as usize;
219219

220220
let ikpoint = if self.ikpoint > 0 && self.ikpoint <= wav.nkpoints as usize {
221221
self.ikpoint - 1

src/commands/vib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct Vib {
5959
/// Modulate the ground-state POSCAR with respect to a certern vibration frequencies.
6060
modulate: bool,
6161

62-
#[arg(short = 'a', long, default_value = "0.1")]
62+
#[arg(short = 'a', long, default_value_t = 0.1)]
6363
/// Modulation amplitude coefficient, to avoid precision issue, abs(amplitude) >= 0.01 should
6464
/// be satisfied.
6565
amplitude: f64,

src/commands/wav1d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Wav1D {
3636
/// WAVECAR file name.
3737
wavecar: PathBuf,
3838

39-
#[arg(long, short = 's', default_value = "1", num_args(0..))]
39+
#[arg(long, short = 's', default_value = "1", num_args(0..=2))]
4040
/// Select spin index, starting from 1.
4141
ispins: Vec<i32>,
4242

src/commands/wav3d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct Wav3D {
4242
/// POSCAR filename, POSCAR is needed to get the real-space wavefunction.
4343
poscar: PathBuf,
4444

45-
#[arg(long, short = 's', default_value = "1", num_args(0..))]
45+
#[arg(long, short = 's', default_value = "1", num_args(0..=2))]
4646
/// Select spin index, starting from 1.
4747
ispins: Vec<i32>,
4848

0 commit comments

Comments
 (0)