github_cli 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +4 -1
  4. data/github_cli.gemspec +3 -1
  5. data/lib/github_cli/dsl.rb +7 -3
  6. data/lib/github_cli/thor_ext.rb +1 -3
  7. data/lib/github_cli/vendor/thor/actions/create_file.rb +105 -0
  8. data/lib/github_cli/vendor/thor/actions/create_link.rb +57 -0
  9. data/lib/github_cli/vendor/thor/actions/directory.rb +98 -0
  10. data/lib/github_cli/vendor/thor/actions/empty_directory.rb +153 -0
  11. data/lib/github_cli/vendor/thor/actions/file_manipulation.rb +308 -0
  12. data/lib/github_cli/vendor/thor/actions/inject_into_file.rb +109 -0
  13. data/lib/github_cli/vendor/thor/actions.rb +318 -0
  14. data/lib/github_cli/vendor/thor/base.rb +641 -0
  15. data/lib/github_cli/vendor/thor/core_ext/dir_escape.rb +0 -0
  16. data/lib/github_cli/vendor/thor/core_ext/file_binary_read.rb +9 -0
  17. data/lib/github_cli/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  18. data/lib/github_cli/vendor/thor/core_ext/ordered_hash.rb +100 -0
  19. data/lib/github_cli/vendor/thor/empty.txt +0 -0
  20. data/lib/github_cli/vendor/thor/error.rb +35 -0
  21. data/lib/github_cli/vendor/thor/group.rb +285 -0
  22. data/lib/github_cli/vendor/thor/invocation.rb +170 -0
  23. data/lib/github_cli/vendor/thor/parser/argument.rb +74 -0
  24. data/lib/github_cli/vendor/thor/parser/arguments.rb +171 -0
  25. data/lib/github_cli/vendor/thor/parser/option.rb +121 -0
  26. data/lib/github_cli/vendor/thor/parser/options.rb +178 -0
  27. data/lib/github_cli/vendor/thor/parser.rb +4 -0
  28. data/lib/github_cli/vendor/thor/rake_compat.rb +71 -0
  29. data/lib/github_cli/vendor/thor/runner.rb +321 -0
  30. data/lib/github_cli/vendor/thor/shell/basic.rb +389 -0
  31. data/lib/github_cli/vendor/thor/shell/color.rb +144 -0
  32. data/lib/github_cli/vendor/thor/shell/html.rb +123 -0
  33. data/lib/github_cli/vendor/thor/shell.rb +88 -0
  34. data/lib/github_cli/vendor/thor/task.rb +132 -0
  35. data/lib/github_cli/vendor/thor/util.rb +266 -0
  36. data/lib/github_cli/vendor/thor/version.rb +3 -0
  37. data/lib/github_cli/vendor/thor.rb +379 -0
  38. data/lib/github_cli/vendor.rb +7 -5
  39. data/lib/github_cli/version.rb +3 -1
  40. metadata +45 -22
  41. data/bin/ghc +0 -2
@@ -0,0 +1,144 @@
1
+ require 'thor/shell/basic'
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class Color < Basic
9
+ # Embed in a String to clear all previous ANSI sequences.
10
+ CLEAR = "\e[0m"
11
+ # The start of an ANSI bold sequence.
12
+ BOLD = "\e[1m"
13
+
14
+ # Set the terminal's foreground ANSI color to black.
15
+ BLACK = "\e[30m"
16
+ # Set the terminal's foreground ANSI color to red.
17
+ RED = "\e[31m"
18
+ # Set the terminal's foreground ANSI color to green.
19
+ GREEN = "\e[32m"
20
+ # Set the terminal's foreground ANSI color to yellow.
21
+ YELLOW = "\e[33m"
22
+ # Set the terminal's foreground ANSI color to blue.
23
+ BLUE = "\e[34m"
24
+ # Set the terminal's foreground ANSI color to magenta.
25
+ MAGENTA = "\e[35m"
26
+ # Set the terminal's foreground ANSI color to cyan.
27
+ CYAN = "\e[36m"
28
+ # Set the terminal's foreground ANSI color to white.
29
+ WHITE = "\e[37m"
30
+
31
+ # Set the terminal's background ANSI color to black.
32
+ ON_BLACK = "\e[40m"
33
+ # Set the terminal's background ANSI color to red.
34
+ ON_RED = "\e[41m"
35
+ # Set the terminal's background ANSI color to green.
36
+ ON_GREEN = "\e[42m"
37
+ # Set the terminal's background ANSI color to yellow.
38
+ ON_YELLOW = "\e[43m"
39
+ # Set the terminal's background ANSI color to blue.
40
+ ON_BLUE = "\e[44m"
41
+ # Set the terminal's background ANSI color to magenta.
42
+ ON_MAGENTA = "\e[45m"
43
+ # Set the terminal's background ANSI color to cyan.
44
+ ON_CYAN = "\e[46m"
45
+ # Set the terminal's background ANSI color to white.
46
+ ON_WHITE = "\e[47m"
47
+
48
+ # Set color by using a string or one of the defined constants. If a third
49
+ # option is set to true, it also adds bold to the string. This is based
50
+ # on Highline implementation and it automatically appends CLEAR to the end
51
+ # of the returned String.
52
+ #
53
+ # Pass foreground, background and bold options to this method as
54
+ # symbols.
55
+ #
56
+ # Example:
57
+ #
58
+ # set_color "Hi!", :red, :on_white, :bold
59
+ #
60
+ # The available colors are:
61
+ #
62
+ # :bold
63
+ # :black
64
+ # :red
65
+ # :green
66
+ # :yellow
67
+ # :blue
68
+ # :magenta
69
+ # :cyan
70
+ # :white
71
+ # :on_black
72
+ # :on_red
73
+ # :on_green
74
+ # :on_yellow
75
+ # :on_blue
76
+ # :on_magenta
77
+ # :on_cyan
78
+ # :on_white
79
+ def set_color(string, *colors)
80
+ if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
81
+ ansi_colors = colors.map { |color| lookup_color(color) }
82
+ "#{ansi_colors.join}#{string}#{CLEAR}"
83
+ else
84
+ # The old API was `set_color(color, bold=boolean)`. We
85
+ # continue to support the old API because you should never
86
+ # break old APIs unnecessarily :P
87
+ foreground, bold = colors
88
+ foreground = self.class.const_get(foreground.to_s.upcase) if foreground.is_a?(Symbol)
89
+
90
+ bold = bold ? BOLD : ""
91
+ "#{bold}#{foreground}#{string}#{CLEAR}"
92
+ end
93
+ end
94
+
95
+ protected
96
+
97
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
98
+ # available.
99
+ #
100
+ def show_diff(destination, content) #:nodoc:
101
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
102
+ actual = File.binread(destination).to_s.split("\n")
103
+ content = content.to_s.split("\n")
104
+
105
+ Diff::LCS.sdiff(actual, content).each do |diff|
106
+ output_diff_line(diff)
107
+ end
108
+ else
109
+ super
110
+ end
111
+ end
112
+
113
+ def output_diff_line(diff) #:nodoc:
114
+ case diff.action
115
+ when '-'
116
+ say "- #{diff.old_element.chomp}", :red, true
117
+ when '+'
118
+ say "+ #{diff.new_element.chomp}", :green, true
119
+ when '!'
120
+ say "- #{diff.old_element.chomp}", :red, true
121
+ say "+ #{diff.new_element.chomp}", :green, true
122
+ else
123
+ say " #{diff.old_element.chomp}", nil, true
124
+ end
125
+ end
126
+
127
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
128
+ # for diff.
129
+ #
130
+ def diff_lcs_loaded? #:nodoc:
131
+ return true if defined?(Diff::LCS)
132
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
133
+
134
+ @diff_lcs_loaded = begin
135
+ require 'diff/lcs'
136
+ true
137
+ rescue LoadError
138
+ false
139
+ end
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,123 @@
1
+ require 'thor/shell/basic'
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class HTML < Basic
9
+ # The start of an HTML bold sequence.
10
+ BOLD = "font-weight: bold"
11
+
12
+ # Set the terminal's foreground HTML color to black.
13
+ BLACK = 'color: black'
14
+ # Set the terminal's foreground HTML color to red.
15
+ RED = 'color: red'
16
+ # Set the terminal's foreground HTML color to green.
17
+ GREEN = 'color: green'
18
+ # Set the terminal's foreground HTML color to yellow.
19
+ YELLOW = 'color: yellow'
20
+ # Set the terminal's foreground HTML color to blue.
21
+ BLUE = 'color: blue'
22
+ # Set the terminal's foreground HTML color to magenta.
23
+ MAGENTA = 'color: magenta'
24
+ # Set the terminal's foreground HTML color to cyan.
25
+ CYAN = 'color: cyan'
26
+ # Set the terminal's foreground HTML color to white.
27
+ WHITE = 'color: white'
28
+
29
+ # Set the terminal's background HTML color to black.
30
+ ON_BLACK = 'background-color: black'
31
+ # Set the terminal's background HTML color to red.
32
+ ON_RED = 'background-color: red'
33
+ # Set the terminal's background HTML color to green.
34
+ ON_GREEN = 'background-color: green'
35
+ # Set the terminal's background HTML color to yellow.
36
+ ON_YELLOW = 'background-color: yellow'
37
+ # Set the terminal's background HTML color to blue.
38
+ ON_BLUE = 'background-color: blue'
39
+ # Set the terminal's background HTML color to magenta.
40
+ ON_MAGENTA = 'background-color: magenta'
41
+ # Set the terminal's background HTML color to cyan.
42
+ ON_CYAN = 'background-color: cyan'
43
+ # Set the terminal's background HTML color to white.
44
+ ON_WHITE = 'background-color: white'
45
+
46
+ # Set color by using a string or one of the defined constants. If a third
47
+ # option is set to true, it also adds bold to the string. This is based
48
+ # on Highline implementation and it automatically appends CLEAR to the end
49
+ # of the returned String.
50
+ #
51
+ def set_color(string, *colors)
52
+ if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
53
+ html_colors = colors.map { |color| lookup_color(color) }
54
+ "<span style=\"#{html_colors.join("; ")};\">#{string}</span>"
55
+ else
56
+ color, bold = colors
57
+ html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
58
+ styles = [html_color]
59
+ styles << BOLD if bold
60
+ "<span style=\"#{styles.join("; ")};\">#{string}</span>"
61
+ end
62
+ end
63
+
64
+ # Ask something to the user and receives a response.
65
+ #
66
+ # ==== Example
67
+ # ask("What is your name?")
68
+ #
69
+ # TODO: Implement #ask for Thor::Shell::HTML
70
+ def ask(statement, color=nil)
71
+ raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
72
+ end
73
+
74
+ protected
75
+
76
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
77
+ # available.
78
+ #
79
+ def show_diff(destination, content) #:nodoc:
80
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
81
+ actual = File.binread(destination).to_s.split("\n")
82
+ content = content.to_s.split("\n")
83
+
84
+ Diff::LCS.sdiff(actual, content).each do |diff|
85
+ output_diff_line(diff)
86
+ end
87
+ else
88
+ super
89
+ end
90
+ end
91
+
92
+ def output_diff_line(diff) #:nodoc:
93
+ case diff.action
94
+ when '-'
95
+ say "- #{diff.old_element.chomp}", :red, true
96
+ when '+'
97
+ say "+ #{diff.new_element.chomp}", :green, true
98
+ when '!'
99
+ say "- #{diff.old_element.chomp}", :red, true
100
+ say "+ #{diff.new_element.chomp}", :green, true
101
+ else
102
+ say " #{diff.old_element.chomp}", nil, true
103
+ end
104
+ end
105
+
106
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
107
+ # for diff.
108
+ #
109
+ def diff_lcs_loaded? #:nodoc:
110
+ return true if defined?(Diff::LCS)
111
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
112
+
113
+ @diff_lcs_loaded = begin
114
+ require 'diff/lcs'
115
+ true
116
+ rescue LoadError
117
+ false
118
+ end
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,88 @@
1
+ require 'rbconfig'
2
+
3
+ class Thor
4
+ module Base
5
+ # Returns the shell used in all Thor classes. If you are in a Unix platform
6
+ # it will use a colored log, otherwise it will use a basic one without color.
7
+ #
8
+ def self.shell
9
+ @shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0
10
+ Thor::Shell.const_get(ENV['THOR_SHELL'])
11
+ elsif ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) && !(ENV['ANSICON']))
12
+ Thor::Shell::Basic
13
+ else
14
+ Thor::Shell::Color
15
+ end
16
+ end
17
+
18
+ # Sets the shell used in all Thor classes.
19
+ #
20
+ def self.shell=(klass)
21
+ @shell = klass
22
+ end
23
+ end
24
+
25
+ module Shell
26
+ SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns, :print_table, :print_wrapped, :file_collision, :terminal_width]
27
+
28
+ autoload :Basic, 'thor/shell/basic'
29
+ autoload :Color, 'thor/shell/color'
30
+ autoload :HTML, 'thor/shell/html'
31
+
32
+ # Add shell to initialize config values.
33
+ #
34
+ # ==== Configuration
35
+ # shell<Object>:: An instance of the shell to be used.
36
+ #
37
+ # ==== Examples
38
+ #
39
+ # class MyScript < Thor
40
+ # argument :first, :type => :numeric
41
+ # end
42
+ #
43
+ # MyScript.new [1.0], { :foo => :bar }, :shell => Thor::Shell::Basic.new
44
+ #
45
+ def initialize(args=[], options={}, config={})
46
+ super
47
+ self.shell = config[:shell]
48
+ self.shell.base ||= self if self.shell.respond_to?(:base)
49
+ end
50
+
51
+ # Holds the shell for the given Thor instance. If no shell is given,
52
+ # it gets a default shell from Thor::Base.shell.
53
+ def shell
54
+ @shell ||= Thor::Base.shell.new
55
+ end
56
+
57
+ # Sets the shell for this thor class.
58
+ def shell=(shell)
59
+ @shell = shell
60
+ end
61
+
62
+ # Common methods that are delegated to the shell.
63
+ SHELL_DELEGATED_METHODS.each do |method|
64
+ module_eval <<-METHOD, __FILE__, __LINE__
65
+ def #{method}(*args,&block)
66
+ shell.#{method}(*args,&block)
67
+ end
68
+ METHOD
69
+ end
70
+
71
+ # Yields the given block with padding.
72
+ def with_padding
73
+ shell.padding += 1
74
+ yield
75
+ ensure
76
+ shell.padding -= 1
77
+ end
78
+
79
+ protected
80
+
81
+ # Allow shell to be shared between invocations.
82
+ #
83
+ def _shared_configuration #:nodoc:
84
+ super.merge!(:shell => self.shell)
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,132 @@
1
+ class Thor
2
+ class Task < Struct.new(:name, :description, :long_description, :usage, :options)
3
+ FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
4
+
5
+ def initialize(name, description, long_description, usage, options=nil)
6
+ super(name.to_s, description, long_description, usage, options || {})
7
+ end
8
+
9
+ def initialize_copy(other) #:nodoc:
10
+ super(other)
11
+ self.options = other.options.dup if other.options
12
+ end
13
+
14
+ def hidden?
15
+ false
16
+ end
17
+
18
+ # By default, a task invokes a method in the thor class. You can change this
19
+ # implementation to create custom tasks.
20
+ def run(instance, args=[])
21
+ arity = nil
22
+
23
+ if private_method?(instance)
24
+ instance.class.handle_no_task_error(name)
25
+ elsif public_method?(instance)
26
+ arity = instance.method(name).arity
27
+ instance.__send__(name, *args)
28
+ elsif local_method?(instance, :method_missing)
29
+ instance.__send__(:method_missing, name.to_sym, *args)
30
+ else
31
+ instance.class.handle_no_task_error(name)
32
+ end
33
+ rescue ArgumentError => e
34
+ handle_argument_error?(instance, e, caller) ?
35
+ instance.class.handle_argument_error(self, e, arity) : (raise e)
36
+ rescue NoMethodError => e
37
+ handle_no_method_error?(instance, e, caller) ?
38
+ instance.class.handle_no_task_error(name) : (raise e)
39
+ end
40
+
41
+ # Returns the formatted usage by injecting given required arguments
42
+ # and required options into the given usage.
43
+ def formatted_usage(klass, namespace = true, subcommand = false)
44
+ if namespace
45
+ namespace = klass.namespace
46
+ formatted = "#{namespace.gsub(/^(default)/,'')}:"
47
+ end
48
+ formatted = "#{klass.namespace.split(':').last} " if subcommand
49
+
50
+ formatted ||= ""
51
+
52
+ # Add usage with required arguments
53
+ formatted << if klass && !klass.arguments.empty?
54
+ usage.to_s.gsub(/^#{name}/) do |match|
55
+ match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
56
+ end
57
+ else
58
+ usage.to_s
59
+ end
60
+
61
+ # Add required options
62
+ formatted << " #{required_options}"
63
+
64
+ # Strip and go!
65
+ formatted.strip
66
+ end
67
+
68
+ protected
69
+
70
+ def not_debugging?(instance)
71
+ !(instance.class.respond_to?(:debugging) && instance.class.debugging)
72
+ end
73
+
74
+ def required_options
75
+ @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
76
+ end
77
+
78
+ # Given a target, checks if this class name is a public method.
79
+ def public_method?(instance) #:nodoc:
80
+ !(instance.public_methods & [name.to_s, name.to_sym]).empty?
81
+ end
82
+
83
+ def private_method?(instance)
84
+ !(instance.private_methods & [name.to_s, name.to_sym]).empty?
85
+ end
86
+
87
+ def local_method?(instance, name)
88
+ methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false)
89
+ !(methods & [name.to_s, name.to_sym]).empty?
90
+ end
91
+
92
+ def sans_backtrace(backtrace, caller) #:nodoc:
93
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) }
94
+ saned -= caller
95
+ end
96
+
97
+ def handle_argument_error?(instance, error, caller)
98
+ not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
99
+ saned = sans_backtrace(error.backtrace, caller)
100
+ # Ruby 1.9 always include the called method in the backtrace
101
+ saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
102
+ end
103
+ end
104
+
105
+ def handle_no_method_error?(instance, error, caller)
106
+ not_debugging?(instance) &&
107
+ error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
108
+ end
109
+ end
110
+
111
+ # A task that is hidden in help messages but still invocable.
112
+ class HiddenTask < Task
113
+ def hidden?
114
+ true
115
+ end
116
+ end
117
+
118
+ # A dynamic task that handles method missing scenarios.
119
+ class DynamicTask < Task
120
+ def initialize(name, options=nil)
121
+ super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
122
+ end
123
+
124
+ def run(instance, args=[])
125
+ if (instance.methods & [name.to_s, name.to_sym]).empty?
126
+ super
127
+ else
128
+ instance.class.handle_no_task_error(name)
129
+ end
130
+ end
131
+ end
132
+ end