Class: Accern::Cli
- Inherits:
-
Object
- Object
- Accern::Cli
- Defined in:
- lib/accern/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
-
#filetype ⇒ Object
readonly
Returns the value of attribute filetype.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#valid_types ⇒ Object
readonly
Returns the value of attribute valid_types.
Instance Method Summary collapse
- #ask_for_filetype ⇒ Object
- #ask_for_token ⇒ Object
-
#initialize(stdout: $stdout, stdin: $stdin, args: [], feed: Alpha) ⇒ Cli
constructor
A new instance of Cli.
- #load_config ⇒ Object
- #parse_options ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stdin: $stdin, args: [], feed: Alpha) ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/accern/cli.rb', line 6 def initialize(stdout: $stdout, stdin: $stdin, args: [], feed: Alpha) @stdout = stdout @stdin = stdin @args = args @options = {} @filetype = 'json' @valid_types = %w(json csv) @config_path = "#{ENV['HOME']}/.accern.rc.yml" @feed = feed end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def args @args end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def config_path @config_path end |
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def feed @feed end |
#filetype ⇒ Object (readonly)
Returns the value of attribute filetype.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def filetype @filetype end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def @options end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def stdout @stdout end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def token @token end |
#valid_types ⇒ Object (readonly)
Returns the value of attribute valid_types.
3 4 5 |
# File 'lib/accern/cli.rb', line 3 def valid_types @valid_types end |
Instance Method Details
#ask_for_filetype ⇒ Object
33 34 35 36 |
# File 'lib/accern/cli.rb', line 33 def ask_for_filetype ask_question('Please enter the file type (JSON or CSV): ', :filetype) valid_filetype? end |
#ask_for_token ⇒ Object
29 30 31 |
# File 'lib/accern/cli.rb', line 29 def ask_for_token ask_question('Please enter your API Token: ', :token) end |
#load_config ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/accern/cli.rb', line 38 def load_config if File.exist?(config_path) config = YAML.load_file(config_path) @token = config[:token] @filetype = config[:filetype] else ask_for_info end end |
#parse_options ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/accern/cli.rb', line 48 def parser = OptionParser.new do |opts| opts. = 'A command line interface for the Accern API' opts.on('--init', 'Display the getting started prompts.') do [:init] = true end opts.on('--version', 'Show version') do [:version] = Accern::VERSION puts Accern::VERSION exit end end parser.parse!(args) end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/accern/cli.rb', line 17 def start load_config if [:init] ask_for_info else feed.new(token: token, format: filetype.to_sym) .download_loop('./feed.jsonl') end end |