Wolfgang Bumiller
7ebb173352
getopt: cleanup: add trailing commas
...
It is customary in rust to always use trailing commas. (also
suggested by rustfmt)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 14:27:38 +01:00
Wolfgang Bumiller
2767c5d39b
getopt: cleanup: don't condense 'if' statements too much
...
In a language which enforces curly braces this looks weird
and rustfmt doesn't like it.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 14:27:38 +01:00
Wolfgang Bumiller
7d95c10da0
getopt: whitespace cleanup
...
to make rustfmt happy
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 14:27:38 +01:00
Wolfgang Bumiller
03fb895197
getopt: condense nested match to reduce indentation
...
The `match value` statement is the only thing covering the
entire RawArgument::Option case. `rustfmt` suggests this
more condensed way of writing this case.
See the `git diff -w` of this patch:
|diff --git a/src/getopts.rs b/src/getopts.rs
|index 9755af2..4db4579 100644
|--- a/src/getopts.rs
|+++ b/src/getopts.rs
|@@ -72,8 +72,7 @@ pub fn parse_arguments<T: AsRef<str>>(
| RawArgument::Separator => {
| break;
| }
|- RawArgument::Option { name, value } => {
|- match value {
|+ RawArgument::Option { name, value } => match value {
| None => {
| let mut want_bool = false;
| let mut can_default = false;
|@@ -125,7 +124,6 @@ pub fn parse_arguments<T: AsRef<str>>(
| data.push((name, v));
| }
| }
|- }
| RawArgument::Argument { value } => {
| rest.push(value);
| }
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 14:16:58 +01:00
Wolfgang Bumiller
4d0ea9978b
getopt: let parse_arguments() take a slice of AsRef<str>
...
We don't need the content to be owned strings, and we don't
need the list to be a Vec, since we only care about being
able to iterate through and copy out portions of the strings
we need, so take an &[T] where T: AsRef<str>.
This avoids .iter().map(to_string).collect() before calling
parse_arguments().
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 14:05:05 +01:00
Wolfgang Bumiller
2482c095b1
getopt: remove skip logic
...
The 'skip' variable was set to indicate that the "rest of
the args" is to be copied into the 'rest' vec. We can do
this directly and avoid the 'if' case in the loop
altogether.
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 13:59:44 +01:00
Wolfgang Bumiller
99da3a073d
getopt: indentation reduction
...
See the `git diff -w` output:
|diff --git a/src/getopts.rs b/src/getopts.rs
|index 6548a01..517cc37 100644
|--- a/src/getopts.rs
|+++ b/src/getopts.rs
|@@ -72,7 +72,10 @@ pub fn parse_arguments(
| while pos < args.len() {
| if skip {
| rest.push(args[pos].clone());
|- } else {
|+ pos += 1;
|+ continue;
|+ }
|+
| match parse_argument(&args[pos]) {
| RawArgument::Separator => {
| skip = true;
|@@ -135,7 +138,6 @@ pub fn parse_arguments(
| rest.push(value);
| }
| }
|- }
|
| pos += 1;
| }
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 13:54:20 +01:00
Wolfgang Bumiller
ad8a98f7e4
parse_arguments: work with utf8 bytes and reduce indentation
...
We are only caring about '=' and '-' which are single-byte
codepoints, so there's no reason not to work on a byte
slice.
Also, some indentation reduction:
Transform
if (a) {
...
return A;
}
return B;
into
if (!a)
return B;
return A;
and
if (a)
if (b)
foo()
into
if (a && b)
return;
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-12-28 13:47:29 +01:00
Dietmar Maurer
b22751b20c
getopts.rs: fix test
2018-12-07 09:02:24 +01:00
Dietmar Maurer
73f29c34d7
improve command line parser
2018-11-30 12:10:26 +01:00
Dietmar Maurer
bfb1d69abc
fix compiler warnings, add storage/config.rs
2018-11-30 11:15:26 +01:00
Dietmar Maurer
768e01091a
implement Into Arc<Schema>
2018-11-23 13:18:41 +01:00
Dietmar Maurer
7edeec7b06
remove parameter macro, implement ObjectSchema builder
...
And store "optional" attribute inside properties hash.
2018-11-23 11:34:15 +01:00
Dietmar Maurer
82df76fff0
start using builder pattern instead of macros
2018-11-23 09:55:38 +01:00
Dietmar Maurer
00c908df85
use Arc pointer to properties
2018-11-20 17:20:50 +01:00
Dietmar Maurer
be45ccd203
fix getopts when called without any argument
2018-11-18 14:57:18 +01:00
Dietmar Maurer
a19f223dea
impl argument parameters
2018-11-18 10:09:13 +01:00
Dietmar Maurer
c78bcf07ad
getopts: more tests
2018-11-18 09:34:43 +01:00
Dietmar Maurer
62c40162ee
improve getopt parser
2018-11-18 08:55:21 +01:00
Dietmar Maurer
a653882dd9
use ObjectSchema for parameters
...
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-11-18 08:46:26 +01:00
Dietmar Maurer
5d9f0eae6b
another testcase for boolean argument parser
2018-11-17 11:29:42 +01:00
Dietmar Maurer
2770fbf3c3
getopt parser fixes and cleanups
2018-11-17 11:28:26 +01:00
Dietmar Maurer
7556cab45e
getopts: allow "-option" and "--option"
2018-11-17 10:02:35 +01:00
Dietmar Maurer
0c9ce2bbf0
getopts: improve error handling
2018-11-17 09:57:26 +01:00
Dietmar Maurer
ffff48fcfe
cleanup variable names
2018-11-16 16:47:23 +01:00
Dietmar Maurer
845901f41d
implement getopt parser - first try
2018-11-16 13:14:11 +01:00