-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
335 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't | ||
# have this method, so we add it so we get resolved symlinks | ||
# and compatibility | ||
unless File.respond_to? :realpath | ||
class File #:nodoc: | ||
def self.realpath path | ||
return realpath(File.readlink(path)) if symlink?(path) | ||
path | ||
end | ||
end | ||
end | ||
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib') | ||
require 'rubygems' | ||
require 'gli' | ||
require 'issues' | ||
|
||
include GLI | ||
|
||
program_desc 'GitHub Issues Command Line Interface' | ||
|
||
version Issues::VERSION | ||
|
||
config_file '.issuesrc' | ||
|
||
desc 'username' | ||
arg_name 'username' | ||
flag [:u, :username] | ||
|
||
desc 'password' | ||
arg_name 'password' | ||
flag [:p, :password] | ||
|
||
desc 'repository' | ||
arg_name 'owner/repo' | ||
flag [:r, :repo] | ||
|
||
desc 'List of Issues' | ||
command :list do |c| | ||
c.desc 'milestone' | ||
c.arg_name 'milestone_number' | ||
c.flag [:m, :milestone] | ||
|
||
c.desc 'assignee' | ||
c.arg_name 'username' | ||
c.flag [:a, :assignee] | ||
lib = File.expand_path(File.dirname(__FILE__) + '/../lib') | ||
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) | ||
|
||
c.desc 'list of comma separated Label names. Example: bug,ui,@high' | ||
c.arg_name 'label1,label2' | ||
c.flag [:l, :labels] | ||
|
||
c.desc 'state' | ||
c.arg_name 'state' | ||
c.flag [:s, :state] | ||
|
||
c.action do |global_options,options,args| | ||
Issues::Issue.all.each do |issue| | ||
p issue | ||
end | ||
end | ||
end | ||
|
||
desc 'List of Milestones' | ||
command :milestones do |c| | ||
c.desc 'state' | ||
c.arg_name 'state' | ||
c.default_value 'open' | ||
c.flag [:s, :state] | ||
|
||
c.action do |global_options,options,args| | ||
Issues::Milestone.all.each do |milestone| | ||
p milestone | ||
end | ||
end | ||
end | ||
|
||
|
||
pre do |global,command,options,args| | ||
Issues::Github.username = global[:username] | ||
Issues::Github.password = global[:password] | ||
Issues.repo = Issues::Repo.find(global[:repo]) | ||
true | ||
end | ||
|
||
post do |global,command,options,args| | ||
# Post logic here | ||
# Use skips_post before a command to skip this | ||
# block on that command only | ||
end | ||
|
||
on_error do |exception| | ||
# Error logic here | ||
# return false to skip default error handling | ||
true | ||
end | ||
require 'rubygems' | ||
require 'issues' | ||
|
||
exit GLI.run(ARGV) | ||
exit Issues::Command.run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'optparse' | ||
|
||
require 'issues/command/options' | ||
require 'issues/command/resolver' | ||
|
||
require 'issues/command/base' | ||
require 'issues/command/authenticated' | ||
require 'issues/command/with_repo' | ||
|
||
require 'issues/command/main' | ||
require 'issues/command/help' | ||
require 'issues/command/milestones' | ||
|
||
module Issues | ||
module Command | ||
|
||
def self.run(args) | ||
Main.new(args).run | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Issues | ||
module Command | ||
module Authenticated | ||
|
||
def self.included(base) | ||
base.after_initialize :authenticate | ||
end | ||
|
||
private | ||
def authenticate | ||
Issues::Github.username = options.fetch(:username).value | ||
Issues::Github.password = options.fetch(:password).value | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Issues | ||
module Command | ||
module Base | ||
|
||
def initialize(args) | ||
self.options = Options::Parser.new(self.class, args).parse | ||
run_hooks | ||
end | ||
|
||
def run | ||
success | ||
end | ||
|
||
def self.included(base) | ||
base.send(:include, Options) | ||
base.extend ClassMethods | ||
Resolver.register base | ||
end | ||
|
||
module ClassMethods | ||
|
||
def after_initialize(message) | ||
hooks << message | ||
end | ||
|
||
def hooks | ||
@hooks ||= [] | ||
end | ||
|
||
end | ||
|
||
private | ||
attr_accessor :options | ||
|
||
def hooks | ||
self.class.hooks | ||
end | ||
|
||
def run_hooks | ||
hooks.each do |hook| | ||
send(hook) | ||
end | ||
end | ||
|
||
def success | ||
0 | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Issues | ||
module Command | ||
class Help | ||
include Issues::Command::Base | ||
|
||
def run | ||
puts "help" | ||
|
||
success | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Issues | ||
module Command | ||
|
||
class Main | ||
include Options | ||
|
||
option :repo, '--repo owner/repo', '-r' | ||
option :username, '--username login', '-u' | ||
option :password, '--password password', '-p' | ||
|
||
def initialize(args) | ||
@args = args | ||
end | ||
|
||
def run | ||
Resolver.new(@args).command.run | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Issues | ||
module Command | ||
|
||
class Milestones | ||
include Issues::Command::Base | ||
include Issues::Command::Authenticated | ||
include Issues::Command::WithRepo | ||
|
||
def run | ||
Issues::Milestone.all.each do |milestone| | ||
p milestone | ||
end | ||
|
||
success | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'issues/command/options/option' | ||
require 'issues/command/options/group' | ||
require 'issues/command/options/parser' | ||
|
||
module Issues | ||
module Command | ||
module Options | ||
|
||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def options | ||
@options ||= Group.new(global_options) | ||
end | ||
|
||
def option(name, *args) | ||
options << Option.new(name, args) | ||
end | ||
|
||
private | ||
def global_options | ||
Main.options unless self == Main | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Issues | ||
module Command | ||
module Options | ||
|
||
class Group | ||
extend Forwardable | ||
def_delegators :options, :each, :find, :<< | ||
|
||
def initialize(options = []) | ||
options ||= [] | ||
options.each do |option| | ||
self << option | ||
end | ||
end | ||
|
||
def fetch(name) | ||
find { |option| option.name == name.to_s } | ||
end | ||
|
||
private | ||
def options | ||
@options ||= [] | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Issues | ||
module Command | ||
module Options | ||
|
||
class Option | ||
attr_accessor :name, :args, :value | ||
def initialize(name, args) | ||
self.name, self.args = name, args | ||
end | ||
|
||
def name=(name) | ||
@name = name.to_s | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Issues | ||
module Command | ||
module Options | ||
|
||
class Parser | ||
def initialize(klass, args) | ||
self.klass, self.args = klass, args | ||
end | ||
|
||
def parse | ||
parser.parse!(args) | ||
|
||
options | ||
end | ||
|
||
private | ||
attr_accessor :klass, :args | ||
def options | ||
klass.options | ||
end | ||
|
||
def parser | ||
OptionParser.new do |parser| | ||
options.each do |option| | ||
parser.on(*option.args) do |value| | ||
option.value = value | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.