aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAge
* Merge otp_set function into commands.rsDaniel Mueller2020-04-10
| | | | | | | | | Now that we have isolated and separated out structopt specific definitions into a new module, arg_defs, args.rs is actually so small that we do not want to keep it around any longer. This change marks a first step moving us closer towards removing it. Specifically, it merges the otp_set function from args.rs into the function of the same name in commands.rs.
* Update minimum required Rust version to 1.40.0Daniel Mueller2020-04-05
| | | | | | This change updates the minimum required version of Rust to 1.40.0. Among other changes, this version stabilized std::mem::take, which is something we will use with subsequent changes.
* Add test for bash completion functionalityDaniel Mueller2020-04-05
| | | | | | | | | This change adds a test for the previously introduced bash completion functionality. To test the generated completion script, we spin up a bash instance, source the script, and then perform a completion as the shell would do it. It seems impossible to convince compgen to do the heavy lifting for us and so we invoke the completion function with the expected environment variables present.
* Add support for generating a bash completion scriptDaniel Mueller2020-04-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | This change adds support for generating a bash completion script. If sourced, the shell will provide tab completions for the program's arguments. There are two possible approaches provided by clap for going about generating shell completion functionality: either at build time, by separately generating the clap parsers out-of-band, or at run time, as an option to the main program itself. We are generally not too much in favor of a run time approach, as it means less inspectability at installation time and more overhead in the form of code crammed into the main binary. Hence, with this change we take the "build time" approach. Clap recommends hooking the generation up in build.rs, but this seems like an inflexible choice. For one, that is because it would mean unconditionally generating this file or using some user-unfriendly environment variable based approach for making the process conditional. But there is also the fact that specifying the command for which to generate the script should likely be configurable. That is a limitation of the completion script that clap generates (see https://github.com/clap-rs/clap/issues/1764). In our version we provide a utility program that emits the completion script to standard output, accepting regular command line options itself. In doing so we allow for installation time generation of the completion script or installation of the utility itself, the output of which could be sourced on demand -- depending on the user's preference.
* Move dependencies to args and commands modules into generated codeDaniel Mueller2020-04-04
| | | | | | | | | | | We are aiming to rid the arg_defs module of dependencies to the rest of the crate in an attempt to make the file fully free standing. The last remaining references into the crate are used to hook up the functionality backing the respective commands. Luckily for us, this "gluing" of functionality to types is really only required in the macro-generated code (which we do not care about as part of this exercise) and so with this change we remove the use declarations from the top of the file and reference the respective functionality in an absolute manner instead.
* Remove dependency on crate::Error from arg_defsDaniel Mueller2020-04-04
| | | | | | | | | 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.
* Move PinType type into arg_defs moduleDaniel Mueller2020-04-02
| | | | | | | | 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.
* Factor out arg_defs.rs for argument parsing related typesDaniel Mueller2020-04-01
| | | | | | | | 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.
* Bump version to 0.3.2Daniel Mueller2020-03-31
| | | | | | | | | | | | | | | | This change bumps the version of the crate to 0.3.2. The following notable changes have been made since 0.3.1: - Added the list command that lists all attached Nitrokey devices - Reworked argument handling: - Added structopt dependency in version 0.3.7 - Replaced argparse with structopt - Removed argparse dependency - Made the --verbose and --model options global - Removed vendored dependencies and moved source code into repository root - Bumped nitrokey dependency to 0.6.0 - Bumped quote dependency to 1.0.3 - Bumped syn dependency to 1.0.14
* Fix link to Nitrokey Storage device in READMEDaniel Mueller2020-03-29
| | | | | | The Nitrokey team changed the URL where details about the Nitrokey Storage device are to be found, rendering our link broken. This change updates the link to reference the new location.
* Update quote dependency to 1.0.3Daniel Mueller2020-03-25
| | | | This change updates the quote crate to version 1.0.3.
* Remove deprecated plugin_as_library lint usageDaniel Mueller2020-03-22
| | | | | | 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.
* Update syn dependency to 1.0.14Daniel Mueller2020-03-16
| | | | This change updates the syn crate to version 1.0.14.
* Update nitrokey dependency to 0.6.0Robin Krahl2020-01-29
| | | | | | 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.
* doc: Remove options from synopsis in man pageRobin Krahl2020-01-29
| | | | | | | As it is no longer required to set the global options before the command and as we will probably introduce more global options with the next releases, this patch removes the global options from the synopsis line in the man page. See issue #102 for more details.
* Make --verbose and --model options globalRobin Krahl2020-01-26
| | | | | | | | | 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
* Provide correct mutual exclusion between config set -o and -O optionsDaniel Mueller2020-01-24
| | | | | | | | | | 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.
* Add unit tests for the list commandRobin Krahl2020-01-14
|
* Document the list command in the manpageRobin Krahl2020-01-14
|
* Implement list commandRobin Krahl2020-01-14
| | | | | | | | | | | | | | | 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
* Add scaffolding for the list commandRobin Krahl2020-01-14
| | | | | This patch adds the basic scaffolding for the list command which will list all attached Nitrokey devices.
* Bump nitrokey dependency to version 0.5.1Robin Krahl2020-01-14
| | | | | | 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.
* Use symbolic default values where possibleDaniel Mueller2020-01-08
| | | | | | | | | | 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.
* Do not declare internally used types as pubDaniel Mueller2020-01-08
| | | | | | | | 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.
* Remove empty Args structs for simple (sub-)commandsRobin Krahl2020-01-08
| | | | | | 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.
* Move doc comments for (sub-)commands to their enumRobin Krahl2020-01-08
| | | | | | | 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.
* Handle doc comments and empty variants in the Command! macroRobin Krahl2020-01-08
| | | | | | | | 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.
* Order members in args.rs by command hierarchyRobin Krahl2020-01-08
| | | | | | | | | | | | | | | 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
* Set possible values for all enum options and argumentsRobin Krahl2020-01-07
| | | | | | | 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.
* Add all_str function to enums generated by Enum! macroRobin Krahl2020-01-07
| | | | | | | | | 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!.
* Use closures instead of command functionsRobin Krahl2020-01-07
| | | | | To simplify the code, this patch replaces the one-line argument handling functions with closures.
* Remove str argument from Command! macroRobin Krahl2020-01-07
| | | | | | | 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.
* Remove unused code after structopt transitionRobin Krahl2020-01-07
| | | | | | 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.
* Remove argparse dependencyRobin Krahl2020-01-07
| | | | | | As we have replaced argparse with structopt, we no longer need it as a dependency. This patch removes the dependency from Cargo.toml and deletes the included copy.
* Replace argparse with structoptRobin Krahl2020-01-07
| | | | | | | | | | | | 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.
* Add data structures for the options and argumentsRobin Krahl2020-01-07
| | | | | | 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.
* Derive structopt::StructOpt in Command!Robin Krahl2020-01-07
| | | | | | 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.
* Implement Default in the Enum! and Command! macrosRobin Krahl2020-01-07
| | | | | | | 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.
* Allow adding fields to an enum variant in Command!Robin Krahl2020-01-07
| | | | | | 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.
* Factor out Enum! and Command! macros in arg_utilRobin Krahl2020-01-07
| | | | | For easier refactoring, we remove the internal enum_int! macro and instead copy its code to the Enum! and Command! macros.
* Use strings instead of Command variantsRobin Krahl2020-01-07
| | | | | | | | | 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.
* arg_util: Change Err type in FromStr implementationRobin Krahl2020-01-07
| | | | | structopt requires that FromStr::Err implements std::fmt::Display. Therefore we now return a String that contains a list of allowed values.
* Refactor the Enum! macro into Enum! and Command!Robin Krahl2020-01-07
| | | | | | 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).
* Add structopt dependency in version 0.3.7Daniel Mueller2020-04-04
| | | | | This patch series replaces argparse with structopt in the argument handling code. As a first step, we need structopt as a dependency.
* Move nitrocli source code into repository rootDaniel Mueller2020-04-04
| | | | | | 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.
* Remove vendored dependenciesDaniel Mueller2020-04-04
| | | | | | | | | | | | | | | | | | | | | | | | While it appears that by now we actually can get successful builds without Cargo insisting on Internet access by virtue of using the --frozen flag, maintaining vendored dependencies is somewhat of a pain point. This state will also get worse with upcoming changes that replace argparse in favor of structopt and pull in a slew of new dependencies by doing so. Then there is also the repository structure aspect, which is non-standard due to the way we vendor dependencies and a potential source of confusion. In order to fix these problems, this change removes all the vendored dependencies we have. Delete subrepo argparse/:argparse Delete subrepo base32/:base32 Delete subrepo cc/:cc Delete subrepo cfg-if/:cfg-if Delete subrepo getrandom/:getrandom Delete subrepo lazy-static/:lazy-static Delete subrepo libc/:libc Delete subrepo nitrokey-sys/:nitrokey-sys Delete subrepo nitrokey/:nitrokey Delete subrepo rand/:rand
* Update packaging instruction for Debian and UbuntuRobin Krahl2020-01-04
| | | | | | | | | This patch updates the packaging instruction for Debian: Instead of updating the TODO.rst file, we now have to create a RFS file in the source directory. This patch also adds links to the trackers for the Debian and Ubuntu packages.
* Update links to Debian & Ubuntu packagesDaniel Mueller2020-01-03
| | | | | | | | | | This change updates the links to the Debian & Ubuntu packages in the README. The previously used links were release-specific, which makes them prone to becoming outdated over time. The new Debian link now is to "stable", which is updated automatically as time goes on and new releases are made. For Ubuntu, there is no such meta release and so we link the search results instead, which fulfill a similar purpose.
* Bump version to 0.3.1Daniel Mueller2020-01-03
| | | | | | | | | | | This change bumps the version of the crate to 0.3.1. The following notable changes have been made since 0.3.0: - Added note about interaction with GnuPG to README file - Bumped nitrokey dependency to 0.4.0 - Bumped nitrokey-sys dependency to 3.5.0 - Added lazy_static dependency in version 1.4.0 - Added cfg-if dependency in version 0.1.10 - Added getrandom dependency in version 0.1.13
* Update nitrokey crate to 0.4.0Daniel Mueller2020-01-02
| | | | | | | | | | | | | This change finally updates the version of the nitrokey crate that we consume to 0.4.0. Along with that we update rand_core, one of its dependencies, to 0.5.1. Further more we add cfg-if in version 0.1.10 and getrandom in version 0.1.13, both of which are now new (non-development) dependencies. Import subrepo nitrokey/:nitrokey at e81057037e9b4f370b64c0a030a725bc6bdfb870 Import subrepo cfg-if/:cfg-if at 4484a6faf816ff8058088ad857b0c6bb2f4b02b2 Import subrepo getrandom/:getrandom at d661aa7e1b8cc80b47dabe3d2135b3b47d2858af Import subrepo rand/:rand at d877ed528248b52d947e0484364a4e1ae59ca502