Skip to content

Commit

Permalink
Add default implementations for formats
Browse files Browse the repository at this point in the history
This is "self-document" the intent and codify the default value for the
input and output formats.
  • Loading branch information
volks73 committed Mar 24, 2021
1 parent 4df1b65 commit ef3e669
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/asciicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,37 @@ 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,
TermSheets,
Asciicast,
}

impl Default for OutputFormats {
fn default() -> Self {
Self::Asciicast
}
}

#[derive(Debug, StructOpt)]
#[structopt(settings(&[
clap::AppSettings::NoBinaryName,
Expand Down Expand Up @@ -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"
)]
Expand All @@ -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"
Expand Down

0 comments on commit ef3e669

Please sign in to comment.