Sha256: fa5e6ca92b280ec9e6ee3f34beef7489cf6af8da28607ab03169d81632b9377e
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
require 'internet' require 'views/cli' require 'use_cases/new' require 'use_cases/list' require 'settings_file' module Idonethis::Adapters class Cli class << self def run(argv={}) args = parse(argv) command,*rest = argv args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)}) credential = Settings.credential log(args).call "args: #{args}, command: #{command}, rest: #{rest}" use_cases = { list: Idonethis::UseCases::List.method(:apply), new: Idonethis::UseCases::New.method(:apply), config: Idonethis::UseCases::Config.method(:apply), git: Idonethis::UseCases::Git.method(:apply), help: ->(credential, args) { puts "TODO: implement help" } } use_case = use_cases[command.to_sym] unless use_case puts "No command <#{command.to_sym}> found" return end use_case.call credential, args end private def log(args={}) args[:verbose] == true ? ->(msg){puts "[LOG] #{msg}"} : ->(_){} end def parse(argv={}) args = {} require 'optparse' OptionParser.new do |opts| opts.banner = "Usage: command [options]" opts.on("-v", "--verbose", "Run verbosely") do |v| args[:verbose] = v end opts.on("-m MESSAGE", "Message") do |m| args[:message] = m end opts.on("-d", "Dry run") do |_| args[:dry_run] = true end end.parse! args end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
idonethis-cli-0.5.0 | lib/adapters/cli.rb |
idonethis-cli-0.4.1 | lib/adapters/cli.rb |