mirror of
https://github.com/mistergibson/gxg-web-client.git
synced 2026-10-19 07:39:44 -07:00
Initial Commit
This commit is contained in:
parent
356ad3315b
commit
81daf6f387
283 changed files with 130672 additions and 1 deletions
51
gxg/standard/optparse/ac.rb
Normal file
51
gxg/standard/optparse/ac.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# frozen_string_literal: false
|
||||
require 'optparse'
|
||||
|
||||
class OptionParser::AC < OptionParser
|
||||
private
|
||||
|
||||
def _check_ac_args(name, block)
|
||||
unless /\A\w[-\w]*\z/ =~ name
|
||||
raise ArgumentError, name
|
||||
end
|
||||
unless block
|
||||
raise ArgumentError, "no block given", ParseError.filter_backtrace(caller)
|
||||
end
|
||||
end
|
||||
|
||||
def _ac_arg_enable(prefix, name, help_string, block)
|
||||
_check_ac_args(name, block)
|
||||
|
||||
sdesc = []
|
||||
ldesc = ["--#{prefix}-#{name}"]
|
||||
desc = [help_string]
|
||||
q = name.downcase
|
||||
enable = Switch::NoArgument.new(nil, proc {true}, sdesc, ldesc, nil, desc, block)
|
||||
disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, block)
|
||||
top.append(enable, [], ["enable-" + q], disable, ['disable-' + q])
|
||||
enable
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def ac_arg_enable(name, help_string, &block)
|
||||
_ac_arg_enable("enable", name, help_string, block)
|
||||
end
|
||||
|
||||
def ac_arg_disable(name, help_string, &block)
|
||||
_ac_arg_enable("disable", name, help_string, block)
|
||||
end
|
||||
|
||||
def ac_arg_with(name, help_string, &block)
|
||||
_check_ac_args(name, block)
|
||||
|
||||
sdesc = []
|
||||
ldesc = ["--with-#{name}"]
|
||||
desc = [help_string]
|
||||
q = name.downcase
|
||||
with = Switch::PlacedArgument.new(*search(:atype, String), sdesc, ldesc, nil, desc, block)
|
||||
without = Switch::NoArgument.new(nil, proc {}, sdesc, ldesc, nil, desc, block)
|
||||
top.append(with, [], ["with-" + q], without, ['without-' + q])
|
||||
with
|
||||
end
|
||||
end
|
||||
18
gxg/standard/optparse/date.rb
Normal file
18
gxg/standard/optparse/date.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: false
|
||||
require 'optparse'
|
||||
require 'date'
|
||||
|
||||
OptionParser.accept(DateTime) do |s,|
|
||||
begin
|
||||
DateTime.parse(s) if s
|
||||
rescue ArgumentError
|
||||
raise OptionParser::InvalidArgument, s
|
||||
end
|
||||
end
|
||||
OptionParser.accept(Date) do |s,|
|
||||
begin
|
||||
Date.parse(s) if s
|
||||
rescue ArgumentError
|
||||
raise OptionParser::InvalidArgument, s
|
||||
end
|
||||
end
|
||||
17
gxg/standard/optparse/kwargs.rb
Normal file
17
gxg/standard/optparse/kwargs.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
require 'optparse'
|
||||
|
||||
class OptionParser
|
||||
def define_by_keywords(options, meth, **opts)
|
||||
meth.parameters.each do |type, name|
|
||||
case type
|
||||
when :key, :keyreq
|
||||
op, cl = *(type == :key ? %w"[ ]" : ["", ""])
|
||||
define("--#{name}=#{op}#{name.upcase}#{cl}", *opts[name]) do |o|
|
||||
options[name] = o
|
||||
end
|
||||
end
|
||||
end
|
||||
options
|
||||
end
|
||||
end
|
||||
7
gxg/standard/optparse/shellwords.rb
Normal file
7
gxg/standard/optparse/shellwords.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: false
|
||||
# -*- ruby -*-
|
||||
|
||||
require 'shellwords'
|
||||
require 'optparse'
|
||||
|
||||
OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
|
||||
11
gxg/standard/optparse/time.rb
Normal file
11
gxg/standard/optparse/time.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: false
|
||||
require 'optparse'
|
||||
require 'time'
|
||||
|
||||
OptionParser.accept(Time) do |s,|
|
||||
begin
|
||||
(Time.httpdate(s) rescue Time.parse(s)) if s
|
||||
rescue
|
||||
raise OptionParser::InvalidArgument, s
|
||||
end
|
||||
end
|
||||
7
gxg/standard/optparse/uri.rb
Normal file
7
gxg/standard/optparse/uri.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: false
|
||||
# -*- ruby -*-
|
||||
|
||||
require 'optparse'
|
||||
require 'uri'
|
||||
|
||||
OptionParser.accept(URI) {|s,| URI.parse(s) if s}
|
||||
71
gxg/standard/optparse/version.rb
Normal file
71
gxg/standard/optparse/version.rb
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# frozen_string_literal: false
|
||||
# OptionParser internal utility
|
||||
|
||||
class << OptionParser
|
||||
def show_version(*pkgs)
|
||||
progname = ARGV.options.program_name
|
||||
result = false
|
||||
show = proc do |klass, cname, version|
|
||||
str = "#{progname}"
|
||||
unless klass == ::Object and cname == :VERSION
|
||||
version = version.join(".") if Array === version
|
||||
str << ": #{klass}" unless klass == Object
|
||||
str << " version #{version}"
|
||||
end
|
||||
[:Release, :RELEASE].find do |rel|
|
||||
if klass.const_defined?(rel)
|
||||
str << " (#{klass.const_get(rel)})"
|
||||
end
|
||||
end
|
||||
puts str
|
||||
result = true
|
||||
end
|
||||
if pkgs.size == 1 and pkgs[0] == "all"
|
||||
self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version|
|
||||
unless cname[1] == ?e and klass.const_defined?(:Version)
|
||||
show.call(klass, cname.intern, version)
|
||||
end
|
||||
end
|
||||
else
|
||||
pkgs.each do |pkg|
|
||||
begin
|
||||
pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)}
|
||||
v = case
|
||||
when pkg.const_defined?(:Version)
|
||||
pkg.const_get(n = :Version)
|
||||
when pkg.const_defined?(:VERSION)
|
||||
pkg.const_get(n = :VERSION)
|
||||
else
|
||||
n = nil
|
||||
"unknown"
|
||||
end
|
||||
show.call(pkg, n, v)
|
||||
rescue NameError
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def each_const(path, base = ::Object)
|
||||
path.split(/::|\//).inject(base) do |klass, name|
|
||||
raise NameError, path unless Module === klass
|
||||
klass.constants.grep(/#{name}/i) do |c|
|
||||
klass.const_defined?(c) or next
|
||||
klass.const_get(c)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def search_const(klass, name)
|
||||
klasses = [klass]
|
||||
while klass = klasses.shift
|
||||
klass.constants.each do |cname|
|
||||
klass.const_defined?(cname) or next
|
||||
const = klass.const_get(cname)
|
||||
yield klass, cname, const if name === cname
|
||||
klasses << const if Module === const and const != ::Object
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue