lib/adapters/cli.rb in idonethis-cli-0.13.3 vs lib/adapters/cli.rb in idonethis-cli-0.14.0
- old
+ new
@@ -7,86 +7,19 @@
module Idonethis::Adapters
class Cli
class << self
def run(argv={})
- args = parse(argv)
-
- command,*rest = argv
+ adapters = {
+ internet: Idonethis::Adapters::Internet,
+ git: Idonethis::Adapters::Git,
+ fs: Idonethis::Adapters::IO::DirectoryInfo,
+ views: { list: Idonethis::Adapters::Views::Cli::List.method(:apply)},
+ settings: Settings,
+ log: ->(msg){puts "[LOG] #{msg}"}}
- command = "help" unless command
-
- log = choose_log(args)
-
- args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
- credential = Settings.credential
-
- log.call "args: #{args}, command: #{command}, rest: #{rest}"
-
- use_case = choose command.to_sym, rest
-
- unless use_case
- log.call "No command <#{command.to_sym}> found"
- return
- end
-
- use_case.call credential, args
+ Idonethis::UseCases::Cli.apply argv, adapters
end
-
- private
-
- def choose(command, opts)
- use_cases = {
- list: Idonethis::UseCases::List.method(:apply),
- new: Idonethis::UseCases::New.method(:apply),
- config: Idonethis::UseCases::Config.method(:apply),
- git: ->(_, args) { Idonethis::UseCases::Git.apply(_, args.merge(git: Idonethis::Adapters::Git, view: ->(msg) { puts msg }, fs: Idonethis::Adapters::IO::DirectoryInfo))},
- help: ->(credential, args) { puts "TODO: implement help" }
- }
-
- if command == :list && opts.include?("teams")
- return ->(credential, args) {
- Idonethis::UseCases::Teams.apply(credential, args.merge(view: Idonethis::Adapters::Views::Cli::Teams.method(:apply)))
- }
- end
-
- use_case = use_cases[command]
- end
-
- def choose_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
-
- opts.on("-t TEAM", "--team TEAM" "Run against this team") do |team_name|
- args[:team] = team_name
- end
-
- opts.on("-s WHEN", "--since WHEN" "Show git commits since when") do |value|
- args[:since] = value
- end
- end.parse!
-
- args
- end
end
end
end
+