Class: Imap::Backup::CLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/cli/options.rb

Overview

Defines option methods for CLI classes

Constant Summary collapse

OPTIONS =

Options common to many commands

[
  {
    name: "accounts",
    parameters: {
      type: :string, aliases: ["-a"],
      desc: "a comma-separated list of accounts (defaults to all configured accounts)"
    }
  },
  {
    name: "config",
    parameters: {
      type: :string, aliases: ["-c"],
      desc: "supply the configuration file path (default: ~/.imap-backup/config.json)"
    }
  },
  {
    name: "erb_configuration",
    parameters: {
      type: :string,
      desc:
      "supply an ERB template file path for configuration. " \
      "This is an alternative to the --config option. " \
      "The file will be processed with ERB before being parsed as JSON. " \
      "This allows use of environment variables and other dynamic content. " \
      "Note that using this option is a potential security risk as it allows " \
      "execution of arbitrary code."
    }
  },
  {
    name: "format",
    parameters: {
      type: :string, desc: "the output type, 'text' for plain text or 'json'", aliases: ["-f"]
    }
  },
  {
    name: "quiet",
    parameters: {
      type: :boolean, desc: "silence all output", aliases: ["-q"]
    }
  },
  {
    name: "refresh",
    parameters: {
      type: :boolean, aliases: ["-r"],
      desc: "in the default 'keep all emails' mode, " \
            "updates flags for messages that are already downloaded"
    }
  },
  {
    name: "verbose",
    parameters: {
      type: :boolean, aliases: ["-v"], repeatable: true,
      desc: "increase the amount of logging. " \
            "Without this option, the program gives minimal output. " \
            "Using this option once gives more detailed output. " \
            "Whereas, using this option twice also shows all IMAP network calls"
    }
  }
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base:) ⇒ Options

Returns a new instance of Options.



73
74
75
# File 'lib/imap/backup/cli/options.rb', line 73

def initialize(base:)
  @base = base
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



10
11
12
# File 'lib/imap/backup/cli/options.rb', line 10

def base
  @base
end

Instance Method Details

#define_optionsObject



77
78
79
80
81
82
83
84
85
# File 'lib/imap/backup/cli/options.rb', line 77

def define_options
  OPTIONS.each do |option|
    base.singleton_class.class_eval do
      define_method("#{option[:name]}_option") do
        method_option(option[:name], **option[:parameters])
      end
    end
  end
end