github_cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_cli (0.1.0)
4
+ github_cli (0.1.1)
5
5
  github_api (~> 0.4.8)
6
6
  thor
7
7
 
@@ -24,3 +24,10 @@ Feature: Github API Commands Search
24
24
  | pattern |
25
25
  | re |
26
26
  | repo |
27
+
28
+ Scenario: No Match
29
+ When I run `ghc list bla`
30
+ Then the output should contain:
31
+ """
32
+ ghc: 'bla' is not a ghc command. See 'ghc --help'.
33
+ """
@@ -41,5 +41,4 @@ Feature: Global Settings
41
41
  Writing new configuration file to /tmp/fakehome/myname
42
42
  """
43
43
 
44
-
45
44
  Scenario: Check for presence of yaml attribute
@@ -14,5 +14,5 @@ module GithubCLI
14
14
  end
15
15
  end
16
16
 
17
- end # Repository
17
+ end # Blob
18
18
  end # GithubCLI
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Tag < API
5
+
6
+ class << self
7
+
8
+ def get(user, repo, sha, params)
9
+ github_api.repos.get_tag user, repo, params
10
+ end
11
+
12
+ def create(user, repo, params)
13
+ github_api.repos.create_tag user, repo, params
14
+ end
15
+ end
16
+
17
+ end # Tag
18
+ end # GithubCLI
@@ -0,0 +1,18 @@
1
+ if defined?(require_relative)
2
+ def require_api(path)
3
+ require_relative "apis/#{path}"
4
+ end
5
+ else
6
+ def require_api(path)
7
+ require "github_cli/apis/#{path}"
8
+ end
9
+ end
10
+
11
+ %w[
12
+ blob
13
+ repository
14
+ tag
15
+ tree
16
+ ].each do |api|
17
+ require_api api
18
+ end
@@ -6,14 +6,10 @@ module GithubCLI
6
6
 
7
7
  def initialize(*args)
8
8
  super
9
- say <<-TEXT
10
-
11
- Github CLI client
12
-
13
- TEXT
14
9
  the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
15
10
  GithubCLI.ui = UI.new(the_shell)
16
11
  GithubCLi.ui.debug! if options["verbose"]
12
+ Terminal.print_program_name
17
13
  end
18
14
 
19
15
  map "repository" => :repo,
@@ -66,20 +62,23 @@ Github CLI client
66
62
  Terminal.print_commands pattern
67
63
  end
68
64
 
69
- desc "blob <command>", "leverage Blobs API"
70
- subcommand "blob", GithubCLI::Blobs
65
+ desc "blob <command>", "Leverage Blobs API"
66
+ subcommand "blob", GithubCLI::Commands::Blobs
67
+
68
+ desc "repo <command>", "Leverage Repositories API"
69
+ subcommand "repo", GithubCLI::Commands::Repositories
71
70
 
72
- desc "repo <command>", "leverage Repositories API"
73
- subcommand "repo", GithubCLI::Repositories
71
+ desc "issue <command>", "Leverage Issues API"
72
+ subcommand "issue", GithubCLI::Commands::Issues
74
73
 
75
- desc "issue <command>", "leverage Issues API"
76
- subcommand "issue", GithubCLI::Issues
74
+ desc "label <command>", "Leverage Labels API"
75
+ subcommand "label", GithubCLI::Commands::Labels
77
76
 
78
- desc "label <command>", "leverage Labels API"
79
- subcommand "label", GithubCLI::Labels
77
+ desc "tag <command>", "Leverage Tags API"
78
+ subcommand "tag", GithubCLI::Commands::Tags
80
79
 
81
- desc "tree <command>", "leverage Trees API"
82
- subcommand "tree", GithubCLI::Trees
80
+ desc "tree <command>", "Leverage Trees API"
81
+ subcommand "tree", GithubCLI::Commands::Trees
83
82
 
84
83
  desc 'version', 'Display Github CLI version.'
85
84
  def version
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'github_cli/command'
4
-
5
3
  module GithubCLI
6
- class Blobs < Command
4
+ class Commands::Blobs < Command
7
5
 
8
6
  namespace :blob
9
7
 
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'github_cli/command'
4
-
5
3
  module GithubCLI
6
- class Issues < Command
4
+ class Commands::Issues < Command
7
5
 
8
6
  namespace :issue
9
7
 
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'github_cli/command'
4
-
5
3
  module GithubCLI
6
- class Labels < Command
4
+ class Commands::Labels < Command
7
5
 
8
6
  namespace :label
9
7
 
@@ -22,7 +20,7 @@ module GithubCLI
22
20
  end
23
21
 
24
22
  method_option :name, :type => :string, :required => true
25
- desc 'update <user>, <repo>', 'Create a label.'
23
+ desc 'update <user>, <repo>', 'Update a label.'
26
24
  method_option :params, :type => :hash
27
25
  def update(user, repo)
28
26
  end
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'github_cli/command'
4
-
5
3
  module GithubCLI
6
- class Repositories < Command
4
+ class Commands::Repositories < Command
7
5
 
8
6
  namespace :repo
9
7
 
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ class Commands::Tags < Command
5
+
6
+ namespace :tag
7
+
8
+ desc 'get <user> <repo> <sha>', 'Get a Tag'
9
+ method_option :recursive, :type => :boolean, :aliases => ["-r"],
10
+ :desc => 'get a tree recursively'
11
+ method_option :params, :type => :hash, :default => {},
12
+ :desc => 'Additonal request parameters e.i per_page:100'
13
+ def get(user, repo, sha)
14
+ Tag.get user, repo, sha, options[:params]
15
+ end
16
+
17
+ desc 'create <user> <repo>', 'Create a Tag Object'
18
+ method_option :params, :type => :hash, :default => {},
19
+ :desc => 'Additonal request parameters e.i per_page:100'
20
+ def create(user, repo)
21
+ Tag.create user, repo, options[:params]
22
+ end
23
+
24
+ end # Tag
25
+ end # GithubCLI
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'github_cli/command'
4
-
5
3
  module GithubCLI
6
- class Trees < Command
4
+ class Commands::Trees < Command
7
5
 
8
6
  namespace :tree
9
7
 
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ module Commands
5
+ autoload :Blobs, 'github_cli/commands/blobs'
6
+ autoload :Issues, 'github_cli/commands/issues'
7
+ autoload :Labels, 'github_cli/commands/labels'
8
+ autoload :Repositories, 'github_cli/commands/repositories'
9
+ autoload :Tags, 'github_cli/commands/tags'
10
+ autoload :Trees, 'github_cli/commands/trees'
11
+ end # Commands
12
+ end # GithubCLI
@@ -3,9 +3,10 @@
3
3
  module GithubCLI
4
4
  class Config
5
5
  COMMAND_KEY = 'commands'
6
+ COMMAND_HELP = 'help'
6
7
 
7
8
  def initialize(config_filename=nil)
8
- @filename = config_filename || '.githubrc'
9
+ @filename = config_filename || local_options_file
9
10
  end
10
11
 
11
12
  def []=(key, value)
@@ -32,7 +33,7 @@ module GithubCLI
32
33
  def save(config)
33
34
  config[COMMAND_KEY] = {}
34
35
  Command.all.each do |cmd|
35
- if !cmd.namespace.empty? && cmd.name != 'help'
36
+ if !cmd.namespace.empty? && cmd.name != COMMAND_HELP
36
37
  config[COMMAND_KEY]["#{cmd.namespace}-#{cmd.name}"] = { }
37
38
  end
38
39
  end
@@ -60,6 +61,22 @@ module GithubCLI
60
61
  end
61
62
  end
62
63
 
64
+ def custom_options_file
65
+ end
66
+
67
+ def local_options_file
68
+ '.githubrc'
69
+ end
70
+
71
+ def global_options_file
72
+ begin
73
+ File.join Thor::Util.user_home, ".githubrc"
74
+ rescue ArgumentError
75
+ GithubCLI.ui.warn "Unable to find ~/.githubrc because the HOME environment variable is not set"
76
+ nil
77
+ end
78
+ end
79
+
63
80
  def set_key(key, value)
64
81
  unless data[key] == value
65
82
  data[key] = value
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ module DSL
5
+ @@program_name = $0.split(/\//)[-1]
6
+ @@error_block = nil
7
+
8
+ # Defines a program name.
9
+ def program_name(name=nil)
10
+ if name
11
+ @@program_name = name
12
+ end
13
+ @@program_name
14
+ end
15
+
16
+ # Defines behaviour on error.
17
+ def on_error(&block)
18
+ @@error_block = block
19
+ end
20
+ end
21
+ end
@@ -10,14 +10,40 @@ module GithubCLI
10
10
  attr_accessor :size
11
11
 
12
12
  def print_commands(pattern=nil)
13
- GithubCLI.ui.info 'Commands:'
14
- Command.all.each do |cmd|
15
- print_command cmd if pattern && cmd.namespace =~ pattern
13
+ GithubCLI.ui.info "Commands:"
14
+
15
+ commands = Command.all.select do |cmd|
16
+ cmd if pattern && cmd.namespace =~ pattern
17
+ end.map do |cmd|
18
+ build_command cmd
19
+ end
20
+
21
+ if !commands.empty?
22
+ GithubCLI.ui.print_table commands, :truncate => true
23
+ else
24
+ print_command_not_found pattern.to_s.gsub(/\W|/, '')[3..-1]
25
+ end
26
+ end
27
+
28
+ def build_command(cmd, indent=3)
29
+ prefix = " " * indent
30
+ if cmd.namespace.empty?
31
+ ["#{prefix + cmd.usage}", cmd.desc]
32
+ else
33
+ ["#{prefix + cmd.namespace} #{cmd.usage}", cmd.desc]
16
34
  end
17
35
  end
18
36
 
19
- def print_command(cmd, usage_text='usage')
20
- GithubCLI.ui.info " ghc #{cmd.namespace} #{cmd.usage}"
37
+ def print_command_not_found(cmd)
38
+ GithubCLI.ui.info "ghc: '#{cmd}' is not a ghc command. See 'ghc --help'."
39
+ end
40
+
41
+ def print_program_name
42
+ GithubCLI.ui.info <<-TEXT
43
+
44
+ #{GithubCLI.program_name}
45
+
46
+ TEXT
21
47
  end
22
48
  end
23
49
 
data/lib/github_cli/ui.rb CHANGED
@@ -31,5 +31,9 @@ module GithubCLI
31
31
  def debug!
32
32
  @debug = true
33
33
  end
34
+
35
+ def print_table(table, options={})
36
+ @shell.print_table table, options
37
+ end
34
38
  end # UI
35
39
  end # GithubCLI
@@ -1,3 +1,3 @@
1
1
  module GithubCLI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/github_cli.rb CHANGED
@@ -7,21 +7,20 @@ require 'github_api'
7
7
  require 'github_cli/version'
8
8
 
9
9
  module GithubCLI
10
- autoload :Config, 'github_cli/config'
11
- autoload :CLI, 'github_cli/cli'
12
- autoload :Terminal, 'github_cli/terminal'
13
- autoload :Blob, 'github_cli/blob'
14
- autoload :Blobs, 'github_cli/blobs'
15
- autoload :Tree, 'github_cli/tree'
16
- autoload :Trees, 'github_cli/trees'
17
- autoload :Repositories, 'github_cli/repositories'
18
- autoload :UI, 'github_cli/ui'
19
-
20
- require "github_cli/api"
21
- require "github_cli/repository"
22
- require "github_cli/issues"
23
- require "github_cli/labels"
24
- require "github_cli/command"
10
+ autoload :DSL, 'github_cli/dsl'
11
+ autoload :Config, 'github_cli/config'
12
+ autoload :CLI, 'github_cli/cli'
13
+ autoload :Command, 'github_cli/command'
14
+ autoload :API, 'github_cli/api'
15
+ autoload :Terminal, 'github_cli/terminal'
16
+ autoload :Commands, 'github_cli/commands'
17
+ autoload :UI, 'github_cli/ui'
18
+
19
+ require 'github_cli/apis'
20
+
21
+ extend DSL
22
+
23
+ program_name 'Github CLI client'
25
24
 
26
25
  class << self
27
26
  attr_writer :ui, :config
@@ -4,7 +4,7 @@ describe GithubCLI::Command do
4
4
 
5
5
  context '#all' do
6
6
  let(:task) { stub(:task, :name => 'create').as_null_object }
7
- let(:klass) { GithubCLI::Repositories }
7
+ let(:klass) { GithubCLI::Commands::Repositories }
8
8
 
9
9
  before do
10
10
  task.stub(:last) { task }
@@ -2,10 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe GithubCLI::Config do
4
4
  let(:filename) { '.githubrc' }
5
+ let(:config_name) { 'simple_config' }
5
6
  let(:path) { "/users/#{filename}" }
6
7
 
7
8
  context 'global' do
8
- let(:config) { GithubCLI::Config.new filename }
9
+ let(:config) { GithubCLI::Config.new fixture_path(config_name) }
9
10
 
10
11
  before do
11
12
  File.stub(:open) { YAML.load fixture('simple_config') }
@@ -89,6 +90,7 @@ describe GithubCLI::Config do
89
90
  end
90
91
 
91
92
  it 'expands relative path' do
93
+ config = GithubCLI::Config.new
92
94
  config.path.should == "#{ENV['HOME']}/#{filename}"
93
95
  end
94
96
  end
data/spec/spec_helper.rb CHANGED
@@ -11,5 +11,9 @@ RSpec.configure do |config|
11
11
  end
12
12
 
13
13
  def fixture(name)
14
- File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name))
14
+ File.read File.expand_path File.join(File.dirname(__FILE__), '..', 'fixtures', name)
15
+ end
16
+
17
+ def fixture_path(name)
18
+ File.expand_path File.join(File.dirname(__FILE__), '..', 'fixtures', name)
15
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-01 00:00:00.000000000 Z
12
+ date: 2012-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_api
16
- requirement: &2151931900 !ruby/object:Gem::Requirement
16
+ requirement: &2151931920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.4.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2151931900
24
+ version_requirements: *2151931920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &2151931320 !ruby/object:Gem::Requirement
27
+ requirement: &2151931300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2151931320
35
+ version_requirements: *2151931300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2151930440 !ruby/object:Gem::Requirement
38
+ requirement: &2151930280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2151930440
46
+ version_requirements: *2151930280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &2151929620 !ruby/object:Gem::Requirement
49
+ requirement: &2151929540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2151929620
57
+ version_requirements: *2151929540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &2151928960 !ruby/object:Gem::Requirement
60
+ requirement: &2151928740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2151928960
68
+ version_requirements: *2151928740
69
69
  description: CLI-based access to GitHub API v3
70
70
  email:
71
71
  - pmurach@gmail.com
@@ -93,18 +93,23 @@ files:
93
93
  - github_cli.gemspec
94
94
  - lib/github_cli.rb
95
95
  - lib/github_cli/api.rb
96
- - lib/github_cli/blob.rb
97
- - lib/github_cli/blobs.rb
96
+ - lib/github_cli/apis.rb
97
+ - lib/github_cli/apis/blob.rb
98
+ - lib/github_cli/apis/repository.rb
99
+ - lib/github_cli/apis/tag.rb
100
+ - lib/github_cli/apis/tree.rb
98
101
  - lib/github_cli/cli.rb
99
102
  - lib/github_cli/command.rb
103
+ - lib/github_cli/commands.rb
104
+ - lib/github_cli/commands/blobs.rb
105
+ - lib/github_cli/commands/issues.rb
106
+ - lib/github_cli/commands/labels.rb
107
+ - lib/github_cli/commands/repositories.rb
108
+ - lib/github_cli/commands/tags.rb
109
+ - lib/github_cli/commands/trees.rb
100
110
  - lib/github_cli/config.rb
101
- - lib/github_cli/issues.rb
102
- - lib/github_cli/labels.rb
103
- - lib/github_cli/repositories.rb
104
- - lib/github_cli/repository.rb
111
+ - lib/github_cli/dsl.rb
105
112
  - lib/github_cli/terminal.rb
106
- - lib/github_cli/tree.rb
107
- - lib/github_cli/trees.rb
108
113
  - lib/github_cli/ui.rb
109
114
  - lib/github_cli/version.rb
110
115
  - spec/github_cli/api_spec.rb
File without changes