Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Unreleased
- Bumped `structopt` dependency to `0.3.17`
- Added the `fill` command that fills the SD card of a Nitrokey Storage device
with random data
- Added the `crossterm` dependency in version `0.17.8`


0.3.4
Expand Down
161 changes: 161 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ version = "1.0"
[dependencies.base32]
version = "0.4.0"

[dependencies.crossterm]
version = "0.17.8"

[dependencies.envy]
version = "0.4.1"

Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub struct Context<'io> {
pub stdout: &'io mut dyn io::Write,
/// The `Write` object used as standard error throughout the program.
pub stderr: &'io mut dyn io::Write,
/// Whether `stdout` is a TTY.
pub is_tty: bool,
/// The admin PIN, if provided through an environment variable.
pub admin_pin: Option<ffi::OsString>,
/// The user PIN, if provided through an environment variable.
Expand All @@ -118,14 +120,20 @@ pub struct Context<'io> {
}

impl<'io> Context<'io> {
fn from_env<O, E>(stdout: &'io mut O, stderr: &'io mut E, config: config::Config) -> Context<'io>
fn from_env<O, E>(
stdout: &'io mut O,
stderr: &'io mut E,
is_tty: bool,
config: config::Config,
) -> Context<'io>
where
O: io::Write,
E: io::Write,
{
Context {
stdout,
stderr,
is_tty,
admin_pin: env::var_os(NITROCLI_ADMIN_PIN),
user_pin: env::var_os(NITROCLI_USER_PIN),
new_admin_pin: env::var_os(NITROCLI_NEW_ADMIN_PIN),
Expand Down Expand Up @@ -154,8 +162,11 @@ fn main() {

let rc = match config::Config::load() {
Ok(config) => {
use crossterm::tty::IsTty as _;

let is_tty = stdout.is_tty();
let args = env::args().collect::<Vec<_>>();
let ctx = &mut Context::from_env(&mut stdout, &mut stderr, config);
let ctx = &mut Context::from_env(&mut stdout, &mut stderr, is_tty, config);

run(ctx, args)
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Nitrocli {
let ctx = &mut crate::Context {
stdout: &mut stdout,
stderr: &mut stderr,
is_tty: false,
admin_pin: self.admin_pin.clone(),
user_pin: self.user_pin.clone(),
new_admin_pin: self.new_admin_pin.clone(),
Expand Down