From ef3e66911dd1fd443a9713ad8b7a23bcb0ce71c3 Mon Sep 17 00:00:00 2001 From: Christopher Field Date: Wed, 24 Mar 2021 11:56:53 -0400 Subject: [PATCH] Add default implementations for formats This is "self-document" the intent and codify the default value for the input and output formats. --- src/asciicast.rs | 1 - src/main.rs | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/asciicast.rs b/src/asciicast.rs index cda1aa8..321ef8a 100644 --- a/src/asciicast.rs +++ b/src/asciicast.rs @@ -26,7 +26,6 @@ use strum::{EnumString, EnumVariantNames, VariantNames}; pub const VERSION: usize = 2; pub const DEFAULT_HEIGHT: &str = "24"; - pub const DEFAULT_SHELL: &str = "/bin/sh"; pub const DEFAULT_TERM: &str = "xterm-256color"; pub const DEFAULT_WIDTH: &str = "80"; diff --git a/src/main.rs b/src/main.rs index 60c4609..d82d1b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,18 +24,24 @@ use std::path::PathBuf; use std::process; use structopt::clap::{self, value_t, ArgMatches}; use structopt::StructOpt; -use strum::{EnumString, EnumVariantNames, VariantNames}; +use strum::{Display, EnumString, EnumVariantNames, VariantNames}; pub const DEFAULT_INTERACTIVE_PROMPT: &str = ">>> "; -#[derive(Debug, EnumString, EnumVariantNames)] +#[derive(Display, Debug, EnumString, EnumVariantNames)] #[strum(serialize_all = "lowercase")] enum InputFormats { Germ, TermSheets, } -#[derive(Debug, EnumString, EnumVariantNames)] +impl Default for InputFormats { + fn default() -> Self { + Self::Germ + } +} + +#[derive(Display, Debug, EnumString, EnumVariantNames)] #[strum(serialize_all = "lowercase")] enum OutputFormats { Germ, @@ -43,6 +49,12 @@ enum OutputFormats { Asciicast, } +impl Default for OutputFormats { + fn default() -> Self { + Self::Asciicast + } +} + #[derive(Debug, StructOpt)] #[structopt(settings(&[ clap::AppSettings::NoBinaryName, @@ -121,7 +133,7 @@ struct Cli { long, possible_values = InputFormats::VARIANTS, case_insensitive = true, - default_value = "germ", + default_value, value_name = "format", env = "GERM_INPUT_FORMAT" )] @@ -139,7 +151,7 @@ struct Cli { long, possible_values = OutputFormats::VARIANTS, case_insensitive = true, - default_value = "asciicast", + default_value, default_value_if("use-germ-format", None, "germ"), value_name = "format", env = "GERM_OUTPUT_FORMAT"