Class: GithubControl::CLI
- Inherits:
-
Object
- Object
- GithubControl::CLI
- Defined in:
- lib/github-control/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #action_name ⇒ Object
- #config ⇒ Object
- #config_filename ⇒ Object
- #console ⇒ Object
- #create_action ⇒ Object
- #current_action ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #inspect ⇒ Object
- #option_parser ⇒ Object
- #options ⇒ Object
- #run ⇒ Object
- #user_config ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
9 10 11 |
# File 'lib/github-control/cli.rb', line 9 def initialize(args) @args = args end |
Class Method Details
.execute(args) ⇒ Object
5 6 7 |
# File 'lib/github-control/cli.rb', line 5 def self.execute(args) new(args).run end |
Instance Method Details
#action_name ⇒ Object
47 48 49 |
# File 'lib/github-control/cli.rb', line 47 def action_name @action_name ||= @args.shift || raise(ProblemWithOptions, "Please provide an action to run") end |
#config ⇒ Object
59 60 61 |
# File 'lib/github-control/cli.rb', line 59 def config @config ||= YAML.load_file(config_filename) end |
#config_filename ⇒ Object
63 64 65 |
# File 'lib/github-control/cli.rb', line 63 def config_filename [:config_filename] || raise(ProblemWithOptions, "You need to provide the path to the YAML filename") end |
#console ⇒ Object
51 52 53 |
# File 'lib/github-control/cli.rb', line 51 def console @console ||= Console.new(user_config) end |
#create_action ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/github-control/cli.rb', line 30 def create_action case action_name when "list" Actions::Repositories.new(self) when "shell" Actions::Shell.new(self) when "collab" Actions::Collaborators.new(self) when "add_collab" Actions::AddCollaborators.new(self) when "remove_collab" Actions::RemoveCollaborators.new(self) else raise ProblemWithOptions, "#{action_name} is not a valid action" end end |
#current_action ⇒ Object
26 27 28 |
# File 'lib/github-control/cli.rb', line 26 def current_action @current_action ||= create_action end |
#inspect ⇒ Object
101 102 103 |
# File 'lib/github-control/cli.rb', line 101 def inspect "#<#{self.class} logged in as #{current_user.name.inspect}>" end |
#option_parser ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/github-control/cli.rb', line 74 def option_parser @option_parser ||= OptionParser.new do |opts| opts. = "Usage: github-control #{@action_name || '[action]'} [options] ..." opts.on_tail("-h", "--help", "Show this message") do $stderr.puts opts exit end opts.on("--debug", "Display debugging information") { [:debug] = true $debug = true } opts.on("-c filename", "--config filename", "Load the config from this YAML file") do |filename| [:config_filename] = filename end opts.on("-v", "--version", "Display the github version, and exit.") do puts "Github Control version #{GithubControl::VERSION}" exit end opts.separator "" end end |
#options ⇒ Object
67 68 69 70 71 72 |
# File 'lib/github-control/cli.rb', line 67 def @options ||= { :debug => false, :argv => @args, } end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/github-control/cli.rb', line 13 def run current_action.(option_parser) option_parser.parse!(@args) current_action.call rescue ProblemWithOptions, OptionParser::ParseError => e puts e.backtrace $stderr.puts $stderr.puts e. $stderr.puts $stderr.puts option_parser exit 2 end |
#user_config ⇒ Object
55 56 57 |
# File 'lib/github-control/cli.rb', line 55 def user_config config["user"] || raise(ProblemWithOptions, "You need to provide user data in the YAML file") end |