quik 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,179 +1,213 @@
1
- # encoding: utf-8
2
-
3
- ### NOTE: wrap gli config into a class
4
- ## see github.com/davetron5000/gli/issues/153
5
-
6
- module Quik
7
-
8
- class Tool
9
- def initialize
10
- LogUtils::Logger.root.level = :info # set logging level to info
11
- end
12
-
13
- def run( args )
14
- puts Quik.banner
15
- Toolii.run( args )
16
- end
17
- end
18
-
19
- ## NOTE: gli added function are class methods (thus, wrap class Toolii in Tool for now)
20
-
21
- class Toolii
22
- extend GLI::App
23
-
24
- def self.logger=(value) @@logger=value; end
25
- def self.logger() @@logger; end
26
-
27
- ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
28
- def self.opts=(value) @@opts = value; end
29
- def self.opts() @@opts; end
30
-
31
-
32
- logger = LogUtils::Logger.root
33
- opts = Opts.new
34
-
35
-
36
- program_desc 'ruby quick starter template script wizard .:. the missing code generator'
37
- version VERSION
38
-
39
-
40
- ## desc 'Use only local (offline) cached data; no (online) remote network access'
41
- ## switch [:l, :local], negatable: false
42
-
43
- desc '(Debug) Show debug messages'
44
- switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
45
-
46
- desc '(Debug) Dry run; run script in simulation for testing'
47
- switch [:test, :dry_run], negatable: false
48
-
49
-
50
- def self.fetch_catalog
51
- ## scripts_dir = "#{Quik.root}/test/data"
52
- ## catalog = Catalog.new( "#{scripts_dir}/scripts.yml" )
53
-
54
- url = "https://github.com/rubyref/scripts/raw/master/scripts.yml"
55
-
56
- puts "GET #{url}".bold.green ## output network access in green bold
57
-
58
- catalog = Catalog.from_url( url )
59
- catalog
60
- end
61
-
62
- def self.fetch_script( name )
63
-
64
- ## first try local version in working folder
65
-
66
- text = ''
67
- local_script = "./#{name}.rb"
68
- if File.exist?( local_script )
69
- text = File.read_utf8( local_script )
70
- else ## fetch remote script
71
- url = "https://github.com/rubyref/scripts/raw/master/#{name}.rb"
72
- ## assume utf8 text encoding for now
73
-
74
- puts "GET #{url}".bold.green ## output network access in green bold
75
-
76
- worker = Fetcher::Worker.new
77
- text = worker.read_utf8!( url )
78
- end
79
-
80
- text
81
- end
82
-
83
-
84
-
85
- desc "List ruby quick starter scripts"
86
- arg_name 'QUERY' # optional search query/filter
87
- command [:list,:ls,:l] do |c|
88
-
89
- c.action do |g,o,args|
90
- ## read in scripts diretory
91
- catalog = fetch_catalog
92
- catalog.list( args[0] ) ## note: pass in filter e.g. args[0]; may be nil (no filter)
93
- puts 'Done.'
94
- end # action
95
- end # command list
96
-
97
-
98
- desc "Run ruby quick starter script"
99
- arg_name 'NAME' # required theme name
100
- command [:new,:n] do |c|
101
-
102
- c.action do |g,o,args|
103
-
104
- name = args[0] || 'gem'
105
-
106
- script = fetch_script( name )
107
- if opts.test?
108
- puts "dry (test) run:"
109
- Builder.load( script, test: true )
110
- else
111
- Builder.load( script )
112
- end
113
-
114
- puts 'Done.'
115
- end # action
116
- end # command setup
117
-
118
-
119
-
120
- desc '(Debug) Test command suite'
121
- command :test do |c|
122
- c.action do |g,o,args|
123
-
124
- puts "hello from test command"
125
- puts "args (#{args.class.name}):"
126
- pp args
127
- puts "o (#{o.class.name}):"
128
- pp o
129
- puts "g (#{g.class.name}):"
130
- pp g
131
-
132
- LogUtils::Logger.root.debug 'test debug msg'
133
- LogUtils::Logger.root.info 'test info msg'
134
- LogUtils::Logger.root.warn 'test warn msg'
135
-
136
- puts 'Done.'
137
- end
138
- end
139
-
140
-
141
-
142
- pre do |g,c,o,args|
143
- opts.merge_gli_options!( g )
144
- opts.merge_gli_options!( o )
145
-
146
- puts Quik.banner
147
-
148
- if opts.verbose?
149
- LogUtils::Logger.root.level = :debug
150
- end
151
-
152
- logger.debug "Executing #{c.name}"
153
- true
154
- end
155
-
156
- post do |global,c,o,args|
157
- logger.debug "Executed #{c.name}"
158
- true
159
- end
160
-
161
-
162
- on_error do |e|
163
- puts
164
- puts "*** error: #{e.message}"
165
-
166
- if opts.verbose?
167
- puts e.backtrace
168
- end
169
-
170
- false # skip default error handling
171
- end
172
-
173
-
174
- ### exit run(ARGV) ## note: use Toolii.run( ARGV ) outside of class
175
-
176
- end # class Toolii
177
-
178
- end # module Quik
179
-
1
+ ################
2
+ ## NOTE: wrap gli config into a class
3
+ ## see github.com/davetron5000/gli/issues/153
4
+
5
+ module Quik
6
+
7
+ class Tool
8
+ def initialize
9
+ LogUtils::Logger.root.level = :info # set logging level to info
10
+ end
11
+
12
+ def run( args )
13
+ puts Quik.banner
14
+ Toolii.run( args )
15
+ end
16
+ end
17
+
18
+
19
+ ## NOTE: gli added function are class methods (thus, wrap class Toolii in Tool for now)
20
+
21
+ class Toolii
22
+ extend GLI::App
23
+
24
+ def self.logger=(value) @@logger=value; end
25
+ def self.logger() @@logger; end
26
+
27
+ ## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
28
+ def self.opts=(value) @@opts = value; end
29
+ def self.opts() @@opts; end
30
+
31
+
32
+ logger = LogUtils::Logger.root
33
+ opts = Opts.new
34
+
35
+
36
+ program_desc 'ruby quick starter template script wizard .:. the missing code generator'
37
+ version VERSION
38
+
39
+
40
+ ## desc 'Use only local (offline) cached data; no (online) remote network access'
41
+ ## switch [:l, :local], negatable: false
42
+
43
+ desc '(Debug) Show debug messages'
44
+ switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
45
+
46
+ desc '(Debug) Dry run; run script in simulation for testing'
47
+ switch [:test, :dry_run], negatable: false
48
+
49
+
50
+
51
+ def self.fetch_catalog
52
+ ## scripts_dir = "#{Quik.root}/test/data"
53
+ ## catalog = Catalog.new( "#{scripts_dir}/scripts.yml" )
54
+
55
+ url = QUIK_SCRIPTS_URL
56
+
57
+ puts "GET #{url}".bold.green ## output network access in green bold
58
+
59
+ catalog = Catalog.from_url( url )
60
+ catalog
61
+ end
62
+
63
+
64
+ def self.fetch_script( name_or_path )
65
+
66
+ ## first try local version in working folder
67
+
68
+ text = ''
69
+
70
+ extname = File.extname( name_or_path )
71
+
72
+
73
+ ## try local first
74
+ ## todo/fix: check in ~/.quik/ dir too?
75
+
76
+ path = if extname == '.rb' && File.exist?( name_or_path )
77
+ name_or_path
78
+ elsif extname == '' && File.exist?( "#{name_or_path}.rb" )
79
+ "#{name_or_path}.rb"
80
+ elsif extname == '' && File.exist?( "~/.quik/#{name_or_path}.rb" )
81
+ "~/.quik/#{name_or_path}.rb" ## todo/check - if (~) shortcut works in windows -too?
82
+ else
83
+ nil
84
+ end
85
+
86
+ if path
87
+ text = File.open( path, 'r:utf-8' ) { |f| f.read }
88
+ else ## try fetch remote script
89
+
90
+ url = nil
91
+
92
+ if name_or_path.index( '/' ).nil? ## assume short-cut name if no (/) in name
93
+ ## do a lookup from catalog!!!
94
+ catalog = fetch_catalog
95
+ rec = catalog.find( name_or_path )
96
+ url = rec['script'] if rec
97
+
98
+ if url.nil?
99
+ puts "!! ERROR - sorry no wizard script found / available for name >#{name_or_path}<"
100
+ exit 1
101
+ end
102
+ else
103
+ ## assume custom github url shortcut
104
+ url = "https://github.com/#{name_or_path}/raw/master/quik.rb"
105
+ end
106
+
107
+ ## assume utf8 text encoding for now
108
+ puts "GET #{url}".bold.green ## output network access in green bold
109
+
110
+ worker = Fetcher::Worker.new
111
+ text = worker.read_utf8!( url )
112
+ end
113
+
114
+ text
115
+ end
116
+
117
+
118
+
119
+ desc "List ruby quick starter scripts"
120
+ arg_name 'QUERY' # optional search query/filter
121
+ command [:list,:ls,:l] do |c|
122
+
123
+ c.action do |g,o,args|
124
+ ## read in scripts diretory
125
+ catalog = fetch_catalog
126
+ catalog.list( args[0] ) ## note: pass in filter e.g. args[0]; may be nil (no filter)
127
+ puts 'Done.'
128
+ end # action
129
+ end # command list
130
+
131
+
132
+ desc "Run ruby quick starter script"
133
+ arg_name 'NAME' # required theme name
134
+ command [:new,:n] do |c|
135
+
136
+ c.action do |g,o,args|
137
+
138
+ name = args[0] || 'gem'
139
+
140
+ script = fetch_script( name )
141
+ if opts.test?
142
+ puts "dry (test) run:"
143
+ Builder.load( script, test: true )
144
+ else
145
+ Builder.load( script )
146
+ end
147
+
148
+ puts 'Done.'
149
+ end # action
150
+ end # command setup
151
+
152
+
153
+
154
+ desc '(Debug) Test command suite'
155
+ command :test do |c|
156
+ c.action do |g,o,args|
157
+
158
+ puts "hello from test command"
159
+ puts "args (#{args.class.name}):"
160
+ pp args
161
+ puts "o (#{o.class.name}):"
162
+ pp o
163
+ puts "g (#{g.class.name}):"
164
+ pp g
165
+
166
+ LogUtils::Logger.root.debug 'test debug msg'
167
+ LogUtils::Logger.root.info 'test info msg'
168
+ LogUtils::Logger.root.warn 'test warn msg'
169
+
170
+ puts 'Done.'
171
+ end
172
+ end
173
+
174
+
175
+
176
+ pre do |g,c,o,args|
177
+ opts.merge_gli_options!( g )
178
+ opts.merge_gli_options!( o )
179
+
180
+ puts Quik.banner
181
+
182
+ if opts.verbose?
183
+ LogUtils::Logger.root.level = :debug
184
+ end
185
+
186
+ logger.debug "Executing #{c.name}"
187
+ true
188
+ end
189
+
190
+ post do |global,c,o,args|
191
+ logger.debug "Executed #{c.name}"
192
+ true
193
+ end
194
+
195
+
196
+ on_error do |e|
197
+ puts
198
+ puts "*** error: #{e.message}"
199
+
200
+ if opts.verbose?
201
+ puts e.backtrace
202
+ end
203
+
204
+ false # skip default error handling
205
+ end
206
+
207
+
208
+ ### exit run(ARGV) ## note: use Toolii.run( ARGV ) outside of class
209
+
210
+ end # class Toolii
211
+
212
+ end # module Quik
213
+
@@ -1,33 +1,33 @@
1
- # encoding: utf-8
2
-
3
- module Quik
4
-
5
- class Opts
6
-
7
- def merge_gli_options!( options = {} )
8
- @test = true if options[:test] == true
9
- @verbose = true if options[:verbose] == true
10
- end
11
-
12
-
13
- def verbose=(boolean) # add: alias for debug ??
14
- @verbose = boolean
15
- end
16
-
17
- def verbose?
18
- return false if @verbose.nil? # default verbose/debug flag is false
19
- @verbose == true
20
- end
21
-
22
- def test=(boolean)
23
- @test = boolean
24
- end
25
-
26
- def test?
27
- return false if @test.nil? # default test/dry-run flag is false
28
- @test == true
29
- end
30
-
31
- end # class Opts
32
-
33
- end # module Quik
1
+ # encoding: utf-8
2
+
3
+ module Quik
4
+
5
+ class Opts
6
+
7
+ def merge_gli_options!( options = {} )
8
+ @test = true if options[:test] == true
9
+ @verbose = true if options[:verbose] == true
10
+ end
11
+
12
+
13
+ def verbose=(boolean) # add: alias for debug ??
14
+ @verbose = boolean
15
+ end
16
+
17
+ def verbose?
18
+ return false if @verbose.nil? # default verbose/debug flag is false
19
+ @verbose == true
20
+ end
21
+
22
+ def test=(boolean)
23
+ @test = boolean
24
+ end
25
+
26
+ def test?
27
+ return false if @test.nil? # default test/dry-run flag is false
28
+ @test == true
29
+ end
30
+
31
+ end # class Opts
32
+
33
+ end # module Quik