command_lion 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,148 @@
1
+ module CommandLion
2
+
3
+
4
+ # The Command class is a fundatmental class for Command Lion.
5
+ #
6
+ # What's kind of nice about it -- at least, I hope -- is that it's actually
7
+ # a very simple class. The `Option` class for Command Lion literally just inhereits from
8
+ # this class so that a Command's options has a specfic namespace, but basically works
9
+ # identically in every other way. This allows you to work out the options for your command
10
+ # in a very simple node-leaf representation. This allows you to naturally work your way down
11
+ # and up the tree as nessecary.
12
+ #
13
+ # Because most of the "keywords" for Command Lion, which are simply ruby methods that behave
14
+ # in a particular way for the Command Lion DSL.
15
+ #
16
+ # == DSL Keywords:
17
+ # description::
18
+ # To provide further context for your application's existence, it's fairly nice to have a description.
19
+ # Like, the usage statement, this can be as complex or as simple as you would like. It isn't required either.
20
+ #
21
+ # == Example
22
+ # app = CommandLion::Command.build do
23
+ # description "Example"
24
+ # end
25
+ #
26
+ # app.description?
27
+ # # => true
28
+ #
29
+ # app.description = "Changed"
30
+ # # => "Changed"
31
+ #
32
+ # app.description
33
+ # # => Changed
34
+ # threaded::
35
+ # To have your command spawn a thread and have the action block
36
+ # for your command run in its own background thread.
37
+ #
38
+ # == Example
39
+ # app = CommandLion::Command.build do
40
+ # description "Example"
41
+ # end
42
+ #
43
+ # app.description?
44
+ # # => true
45
+ #
46
+ # app.description = "Changed"
47
+ # # => "Changed"
48
+ #
49
+ # app.description
50
+ # # => Changed
51
+ #
52
+ #
53
+ class Command < Base
54
+
55
+ simple_attrs :index, :description, :threaded,
56
+ :type, :delimiter, :flags, :arguments,
57
+ :given, :default, :action,
58
+ :options, :before, :after
59
+
60
+ # @private
61
+ def option(index, &block)
62
+ option = Option.new
63
+ option.index = index
64
+ option.instance_eval(&block)
65
+ @options = {} unless @options
66
+ @options[index] = option
67
+ end
68
+
69
+ # @private
70
+ def flags(&block)
71
+ return @flags unless block_given?
72
+ @flags = Flags.build(&block)
73
+ end
74
+
75
+ # @private
76
+ def flag(string = nil)
77
+ if string.nil?
78
+ return @flags.short if @flags
79
+ return nil
80
+ end
81
+ @flags = Flags.build do
82
+ short string.to_s
83
+ end
84
+ end
85
+
86
+ # @private
87
+ def argument
88
+ if arguments.respond_to?(:each)
89
+ arguments.each do |argument|
90
+ # first
91
+ if block_given?
92
+ yield argument
93
+ return
94
+ else
95
+ return argument
96
+ end
97
+ end
98
+ else
99
+ if block_given?
100
+ yield arguments
101
+ return
102
+ else
103
+ return arguments
104
+ end
105
+ end
106
+ nil
107
+ end
108
+
109
+ # @private
110
+ def arguments
111
+ if block_given?
112
+ if @arguments.respond_to?(:each)
113
+ arguments.each do |argument|
114
+ yield argument
115
+ end
116
+ else
117
+ yield @arguments || @default
118
+ end
119
+ else
120
+ @arguments || @default
121
+ end
122
+ end
123
+
124
+ # @private
125
+ def action(&block)
126
+ return @action unless block_given?
127
+ @action = block
128
+ end
129
+
130
+ # @private
131
+ def before(&block)
132
+ return @before unless block_given?
133
+ @before = block
134
+ end
135
+
136
+ # @private
137
+ def after(&block)
138
+ return @after unless block_given?
139
+ @after = block
140
+ end
141
+
142
+ # @private
143
+ def threaded
144
+ @threaded = true
145
+ end
146
+ end
147
+
148
+ end
@@ -0,0 +1,7 @@
1
+ module CommandLion
2
+
3
+ class Flags < Base
4
+ simple_attrs :short, :long
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module CommandLion
2
+ class Option < Command; end
3
+ end
@@ -0,0 +1,31 @@
1
+ module CommandLion
2
+
3
+ module Raw
4
+
5
+ def self.index_of(string)
6
+ ARGV.index(string)
7
+ end
8
+
9
+ def self.arguments_to(string, flags)
10
+ return unless index_of(string)
11
+ args = []
12
+ ARGV.drop(index_of(string)+1).each do |argument|
13
+ next if argument == ","
14
+ break if flags.include?(argument)
15
+ args << argument
16
+ yield argument if block_given?
17
+ end
18
+ args
19
+ end
20
+
21
+ def self.arguments_to?(string)
22
+ ARGV[ARGV.index(string) + 1]
23
+ end
24
+
25
+ def self.argument_to(string)
26
+ ARGV[ARGV.index(string) + 1]
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module CommandLion
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "command_lion/version"
2
+ require "command_lion/raw"
3
+ require "command_lion/base"
4
+ require "command_lion/flags"
5
+ require "command_lion/command"
6
+ require "command_lion/option"
7
+ require "command_lion/app"
8
+
9
+ module CommandLion
10
+ # Your code goes here...
11
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command_lion
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kent 'picat' Gruber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - kgruber1@emich.edu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - ".yardopts"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - command_lion.gemspec
74
+ - examples/debug.rb
75
+ - examples/example.rb
76
+ - examples/example2.rb
77
+ - examples/example_rainbows.rb
78
+ - examples/flipr.rb
79
+ - examples/flipr2.rb
80
+ - examples/flipr3.rb
81
+ - examples/flipr4.rb
82
+ - examples/hello_expanded.rb
83
+ - examples/hello_multi.rb
84
+ - examples/hello_world.rb
85
+ - examples/key_value_example.rb
86
+ - examples/numbers.txt
87
+ - examples/plugin.rb
88
+ - examples/read_file.rb
89
+ - examples/read_stdin.rb
90
+ - examples/readme.rb
91
+ - examples/sample.rb
92
+ - examples/simple_attr_example.rb
93
+ - examples/simple_attrs_example.rb
94
+ - examples/words.txt
95
+ - lib/command_lion.rb
96
+ - lib/command_lion/app.rb
97
+ - lib/command_lion/base.rb
98
+ - lib/command_lion/command.rb
99
+ - lib/command_lion/flags.rb
100
+ - lib/command_lion/option.rb
101
+ - lib/command_lion/raw.rb
102
+ - lib/command_lion/version.rb
103
+ homepage: https://github.com/picatz/command_lion
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.12
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Command-line application framework.
127
+ test_files: []