| Commit message (Collapse) | Author | Age |
|
|
|
|
|
|
|
|
| |
This change removes the need to import crate::Error from the arg_defs
module. By dropping this dependency we make the file more independent of
the rest of the crate, which subsequently will allow us to merely
include! it in another file in order to get the argument related type
definitions without compilation errors due to missing symbols from the
rest of the crate.
|
|
|
|
|
|
|
|
| |
The PinType struct, despite being intended for the pinentry module, is
ultimately part of the argument handling definitions. Because our goal
is to consolidate all of those in a single file, this change moves the
definition of this type from the pinentry module into the newly
introduced arg_defs.
|
|
|
|
|
|
|
|
| |
This change marks the first step in a restructuring of the argument
handling code, the ultimate goal of which is a separation of the type
definitions as used by structopt from the logic associated with it. This
change in particular introduces a new module, arg_defs, that contains
all those type definitions that previously resided in the args module.
|
|
|
|
|
|
| |
The plugin_as_library lint has been deprecated as of Rust 1.40.0. Hence,
with this change we remove it from the list of lints we want to get
warnings from.
|
|
|
|
|
|
| |
nitrokey 0.6.0 introduced the SerialNumber struct (instead of
representing serial numbers as strings). We no longer have to manually
format the serial number as SerialNumber implements Display.
|
|
|
|
|
|
|
|
|
| |
This patch adds the attribute 'global = true' for the top-level
--verbose and --model options, which ensures that they can also be set
for subcommands. For example:
$ nitrocli status --model pro
Instead of only:
$ nitrocli --model pro status
|
|
|
|
|
|
|
|
|
|
| |
The -o/--otp-pin and -O/--no-otp-pin options to the config set command
are supposed to be mutually exclusive, with wrong usage detected by
structopt.
That is not the case currently, however, because the argument to
structopt's conflicts_with attribute is supposed to be the resulting
option and not the name of the variable capturing the result.
This change fixes the problem by changing the string accordingly.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch implements the list command that lists all attached Nitrokey
devices. Currently the Nitrokey Storage does not report its serial
number during HID enumeration, see [0]. So if we detect a Nitrokey
Storage device, we connect to it and use the get_serial_number function
to query its serial number. This can be disabled using the --no-connect
option.
Note that even the get_serial_number function reports a wrong serial
number for the Nitrokey Storage, see [1].
[0] https://github.com/Nitrokey/nitrokey-storage-firmware/issues/88
[1] https://github.com/Nitrokey/nitrokey-storage-firmware/issues/76
|
|
|
|
|
| |
This patch adds the basic scaffolding for the list command which will
list all attached Nitrokey devices.
|
|
|
|
|
|
| |
This change updates the version of the nitrokey crate that we use to
0.5.1. As part of that, it replaces occurrences of Storage::get_status
with Storage::get_storage_status as the method has been renamed.
|
|
|
|
|
|
|
|
|
|
| |
With the switch to using structopt for argument parsing some of the
default values have become mere strings, whereas one of our earlier
objectives was to have symbolic values where that is possible. As
structopt works with symbolic values equally well, this change makes it
use those.
As a bonus, also list the possible formats for the --format option to
the otp set subcommand.
|
|
|
|
|
|
|
|
| |
With the recent patch set moving us to using structopt over argparse we
introduced all new structs and enums representing subcommands and the
like as public. That is unnecessary, as they are not accessed from the
outside.
This change adjusts the visibility accordingly.
|
|
|
|
|
|
| |
Since we updated the Command! macro to also allow enum variants without
fields, we no longer need the empty *Args structs for commands or
subcommands without arguments or options.
|
|
|
|
|
|
|
| |
Since we changed the Command! macro to also support doc comments, we can
now document the commands directly in the enum. This makes the
documentation more consistent when we remove the empty structs for
commands without arguments.
|
|
|
|
|
|
|
|
| |
This patch introduces two changes to the Command! macro:
- We allow variants without fields so that we no longer have to define
empty *Args structs just for the Command! macro.
- We allow doc comments so that we can document commands without a
separate *Args struct.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Currently, the ordering in the args.rs file is inconsistent and
arbitrary. This patch orders the members by command hierarchy:
- common data structures
- for each command C:
- CArgs
- CCommand
- for each subcommand S:
- SArgs
- custom data structures
- custom functions
- main argument handling function
|
|
|
|
|
|
|
| |
This patch adds the possible_values method to the structopt attributes
for all enum options and arguments using the all_str function added in
the previous patch. Therefore, the help messages now also list the
possible values for these options.
|
|
|
|
|
|
|
|
|
| |
To make it easier to list all possible values for a command-line option
mapped to an enum, we add the all_str function to the Enum! macro that
returns an array of the string representations of all variants.
We also use this new function to simplify the generation of the error
message in the FromStr implementation in Enum!.
|
|
|
|
|
| |
To simplify the code, this patch replaces the one-line argument handling
functions with closures.
|
|
|
|
|
|
|
| |
As we no longer have to implement the Display and AsRef traits for the
enums generated with the Command! macro, we don’t have to set a string
representation either. So we can drop this argument from the Command!
macro.
|
|
|
|
|
|
| |
In the previous patches, we replaced argparse with structopt and removed
the argparse dependency. This patch removes the code that was only
needed for argparse.
|
|
|
|
|
|
|
|
|
|
|
|
| |
This patch changes the argument handling code to use structopt instead
of argparse using the data structures we introduced in the last patch.
As part of that transition we replace the old Error::ArgparseError
variant with ClapError that stores a structopt::clap::Error.
Because of that replacement, the format of the help messages changed,
breaking some of the tests. Hence, this change adapts them accordingly.
Also clap currently prints the version output to stdout, so we ignore
the version_option test case for now.
|
|
|
|
|
|
| |
This patch introduces new structs that can be used with structopt to
store the options and arguments parsed from the command line. These
structs use the existing enums and command structs.
|
|
|
|
|
|
| |
As a preparation for the structopt transition, we derive StructOpt for
the enums generated by Command! so that they can be used as a
subcommand.
|
|
|
|
|
|
|
| |
For the transition to structopt, we have to be able to easily construct
enum variants once we have added fields to them. Therefore we implement
the Default trait in the generated macros by choosing the first variant
as the default.
|
|
|
|
|
|
| |
To be able to use the enums generated by Command! with structopt, we
have to be able to add fields to them. This patch adds a new variant to
the Command! macro that supports fields.
|
|
|
|
|
| |
For easier refactoring, we remove the internal enum_int! macro and
instead copy its code to the Enum! and Command! macros.
|
|
|
|
|
|
|
|
|
| |
In one of the next patches, we will add fields to some Command variants
to be able to use them with structopt. Then we will no longer be able
to instantiate them directly, so we replace these instances for the
transition.
This patch also removes the cmd_help! macro that is no longer needed.
|
|
|
|
|
| |
structopt requires that FromStr::Err implements std::fmt::Display.
Therefore we now return a String that contains a list of allowed values.
|
|
|
|
|
|
| |
For an easier transition to structopt, this patch splits the two cases
of the Enum! macro into two separate macros (that internally both call
the new enum_int! macro).
|
|
Now that all vendored dependencies have been removed, this change moves
the program's source code from the nitrocli/ directory into the root of
the repository.
|