Skip to content

Commit

Permalink
Add multivalue arguments
Browse files Browse the repository at this point in the history
- Fixes #33
  • Loading branch information
parasyte committed Feb 19, 2024
1 parent f40e679 commit a1b00a3
Show file tree
Hide file tree
Showing 47 changed files with 501 additions and 68 deletions.
23 changes: 23 additions & 0 deletions onlyargs_derive/compile_tests/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ fn compile_tests() {
t.pass("compile_tests/positional_usize.rs");
t.compile_fail("compile_tests/conflicting_positional.rs");

t.pass("compile_tests/multivalue_f32.rs");
t.pass("compile_tests/multivalue_f64.rs");
t.pass("compile_tests/multivalue_i8.rs");
t.pass("compile_tests/multivalue_i128.rs");
t.pass("compile_tests/multivalue_isize.rs");
t.pass("compile_tests/multivalue_u8.rs");
t.pass("compile_tests/multivalue_u128.rs");
t.pass("compile_tests/multivalue_usize.rs");
t.pass("compile_tests/multivalue_osstring.rs");
t.pass("compile_tests/multivalue_pathbuf.rs");
t.pass("compile_tests/multivalue_string.rs");

t.pass("compile_tests/empty.rs");
t.pass("compile_tests/optional.rs");
t.pass("compile_tests/struct_doc_comment.rs");
Expand All @@ -40,4 +52,15 @@ fn compile_tests() {
t.compile_fail("compile_tests/conflicting_short_name.rs");
t.pass("compile_tests/manual_short_name.rs");
t.pass("compile_tests/ignore_short_name.rs");

// Various expected errors.
t.compile_fail("compile_tests/required_bool.rs");
t.compile_fail("compile_tests/required_option.rs");
t.compile_fail("compile_tests/required_string.rs");
t.compile_fail("compile_tests/default_multivalue.rs");
t.compile_fail("compile_tests/default_option.rs");
t.compile_fail("compile_tests/default_positional.rs");
t.compile_fail("compile_tests/positional_option.rs");
t.compile_fail("compile_tests/positional_single_bool.rs");
t.compile_fail("compile_tests/positional_single_string.rs");
}
2 changes: 2 additions & 0 deletions onlyargs_derive/compile_tests/conflicting_positional.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<String>,
#[positional]
more: Vec<String>,
}

Expand Down
4 changes: 2 additions & 2 deletions onlyargs_derive/compile_tests/conflicting_positional.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Positional arguments can only be specified once.
--> compile_tests/conflicting_positional.rs:4:5
--> compile_tests/conflicting_positional.rs:6:5
|
4 | more: Vec<String>,
6 | more: Vec<String>,
| ^^^^
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/default_multivalue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[default(123)]
nums: Vec<u64>,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/default_multivalue.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[default(...)] can only be used on primitive types
--> compile_tests/default_multivalue.rs:4:11
|
4 | nums: Vec<u64>,
| ^^^
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/default_option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[default(123)]
opt_num: Option<u64>,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/default_option.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[default(...)] can only be used on primitive types
--> compile_tests/default_option.rs:4:14
|
4 | opt_num: Option<u64>,
| ^^^^^^
8 changes: 8 additions & 0 deletions onlyargs_derive/compile_tests/default_positional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
#[default(123)]
nums: Vec<u64>,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/default_positional.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[default(...)] can only be used on primitive types
--> compile_tests/default_positional.rs:5:11
|
5 | nums: Vec<u64>,
| ^^^
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_f32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<f32>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_f64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<f64>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_i128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<i128>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_i8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<i8>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_isize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<isize>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_osstring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
strings: Vec<std::ffi::OsString>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_pathbuf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
paths: Vec<std::path::PathBuf>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
strings: Vec<String>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_u128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<u128>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_u8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<i8>,
}

fn main() {}
6 changes: 6 additions & 0 deletions onlyargs_derive/compile_tests/multivalue_usize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
vertices: Vec<usize>,
}

fn main() {}
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_f32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<f32>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_f64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<f64>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_i128.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<i128>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_i8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<i8>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_isize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<isize>,
}

Expand Down
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/positional_option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Option<i32>,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/positional_option.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[positional] can only be used on `Vec<T>`
--> compile_tests/positional_option.rs:4:11
|
4 | rest: Option<i32>,
| ^^^^^^
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_osstring.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<std::ffi::OsString>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_pathbuf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<std::path::PathBuf>,
}

Expand Down
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/positional_single_bool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: bool,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/positional_single_bool.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[positional] can only be used on `Vec<T>`
--> compile_tests/positional_single_bool.rs:4:11
|
4 | rest: bool,
| ^^^^
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/positional_single_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: String,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/positional_single_string.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[positional] can only be used on `Vec<T>`
--> compile_tests/positional_single_string.rs:4:11
|
4 | rest: String,
| ^^^^^^
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<String>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_u128.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<u128>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_u8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<u8>,
}

Expand Down
1 change: 1 addition & 0 deletions onlyargs_derive/compile_tests/positional_usize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[positional]
rest: Vec<usize>,
}

Expand Down
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/required_bool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[required]
required_bool: bool,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/required_bool.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[required] can only be used on `Vec<T>`
--> compile_tests/required_bool.rs:4:20
|
4 | required_bool: bool,
| ^^^^
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/required_option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[required]
required_option: Option<String>,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/required_option.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[required] can only be used on `Vec<T>`
--> compile_tests/required_option.rs:4:22
|
4 | required_option: Option<String>,
| ^^^^^^
7 changes: 7 additions & 0 deletions onlyargs_derive/compile_tests/required_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, onlyargs_derive::OnlyArgs)]
struct Args {
#[required]
required_string: String,
}

fn main() {}
5 changes: 5 additions & 0 deletions onlyargs_derive/compile_tests/required_string.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[required] can only be used on `Vec<T>`
--> compile_tests/required_string.rs:4:22
|
4 | required_string: String,
| ^^^^^^
Loading

0 comments on commit a1b00a3

Please sign in to comment.