Sha256: 19f12df15d55fa32e90d79c3a0bfd335bd450e55b0b8fdf2ee3db3d3c9668e3d
Contents?: true
Size: 1.72 KB
Versions: 1
Compression:
Stored size: 1.72 KB
Contents
require_relative 'options' module Idonethis::UseCases class App class << self def apply(argv={}, adapters={}) args = Options.parse(argv) command,*rest = argv command = "help" unless command log = args[:verbose] == true ? adapters[:log] : ->(_){} internet = adapters[:internet] views = adapters[:views] || fail("You need to supply the :views adapter") settings = adapters[:settings] || fail("You need to supply the :settings adapters") args.merge!({ opts: rest, log: log, internet: internet, view: views[:list]}) log.call "args: #{args}, command: #{command}, rest: #{rest}" use_case = choose command.to_sym, adapters, views, rest unless use_case log.call "No command <#{command.to_sym}> found" return end use_case.call settings.credential, args end private def choose(command, adapters, views, opts) use_cases = { list: List.method(:apply), new: New.method(:apply), config: Config.method(:apply), git: ->(_, args) { Git.apply(_, args.merge(git: adapters[:git], view: ->(msg) { puts msg }, fs: adapters[:fs]))}, help: ->(credential, args) { puts "TODO: implement help" } } if command == :list && opts.include?("teams") return ->(credential, args) { Teams.apply(credential, args.merge(view: views[:teams])) } end use_case = use_cases[command] end def choose_log(args={}) args[:verbose].true? ? ->(msg){puts "[LOG] #{msg}"} : ->(_){} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
idonethis-cli-0.15.0 | lib/idonethis/use_cases/app.rb |