youplot 0.4.4 → 0.4.5
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.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/youplot/command.rb +2 -20
- data/lib/youplot/parser.rb +87 -38
- data/lib/youplot/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725b5bffb6d597af728d9b57aedea75dbdf62182ab5c211c4ecdca35b686cb69
|
4
|
+
data.tar.gz: 7eb1d48b2ba900f9955b0cb257f95d79646101598b86d841951b3271b55e0d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ead7ed4edd2948b03f14b77256b03aaaef25f69795c61483b1440c2f6572a29b99d90336a0852e56f5f1c1331d8a9ae47bac421e2c444c282e1814658bd464e
|
7
|
+
data.tar.gz: e76b86a9c7ef5df17cc97e1f5b5c860d82c7d7650b6606d687d26ff24664032a52053f3c00bdbd8d072d8b95ce4ab2506f4119ae7ccf75791fcd4e9bd1838d29
|
data/README.md
CHANGED
@@ -211,6 +211,14 @@ The following sub-commands are available.
|
|
211
211
|
|
212
212
|
* Not yet supported.
|
213
213
|
|
214
|
+
### YouPlot Configuration (youplotrc)
|
215
|
+
|
216
|
+
You can specify default options in a configuration file in YAML format. For more information, enter the following command.
|
217
|
+
|
218
|
+
```
|
219
|
+
uplot --config
|
220
|
+
```
|
221
|
+
|
214
222
|
## Tools that are useful to use with YouPlot
|
215
223
|
|
216
224
|
* [csvtk](https://github.com/shenwei356/csvtk)
|
data/lib/youplot/command.rb
CHANGED
@@ -40,24 +40,6 @@ module YouPlot
|
|
40
40
|
return
|
41
41
|
end
|
42
42
|
|
43
|
-
# config command
|
44
|
-
if @command == :config
|
45
|
-
if ENV['MYYOUPLOTRC']
|
46
|
-
puts "config file : #{ENV['MYYOUPLOTRC']}"
|
47
|
-
puts parser.config.inspect
|
48
|
-
else
|
49
|
-
puts <<~EOS
|
50
|
-
You don't have a config file. The default config file paths are:
|
51
|
-
./.youplot.yml, ./.youplotrc, ~/.youplot.yml, ~/.youplotrc
|
52
|
-
You can specify a config file with the environment variable MYYOUPLOTRC.
|
53
|
-
File format is YAML. For example:
|
54
|
-
width : 40
|
55
|
-
height : 20
|
56
|
-
EOS
|
57
|
-
end
|
58
|
-
return
|
59
|
-
end
|
60
|
-
|
61
43
|
# progressive mode
|
62
44
|
if options[:progressive]
|
63
45
|
stop = false
|
@@ -178,9 +160,9 @@ module YouPlot
|
|
178
160
|
@backend.barplot(data, params, count: true, reverse: options[:reverse])
|
179
161
|
when :hist, :histogram
|
180
162
|
@backend.histogram(data, params)
|
181
|
-
when :line, :lineplot
|
163
|
+
when :line, :lineplot, :l
|
182
164
|
@backend.line(data, params, options[:fmt])
|
183
|
-
when :lines, :lineplots
|
165
|
+
when :lines, :lineplots, :ls
|
184
166
|
@backend.lines(data, params, options[:fmt])
|
185
167
|
when :scatter, :s
|
186
168
|
@backend.scatter(data, params, options[:fmt])
|
data/lib/youplot/parser.rb
CHANGED
@@ -29,53 +29,59 @@ module YouPlot
|
|
29
29
|
)
|
30
30
|
|
31
31
|
@params = Parameters.new
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def apply_config_file
|
35
|
+
return if !config_file && find_config_file.nil?
|
36
|
+
|
37
|
+
read_config_file
|
38
|
+
configure
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
+
def config_file_candidate_paths
|
42
|
+
# keep the order of the paths
|
41
43
|
paths = []
|
42
44
|
paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
|
43
45
|
paths << '.youplot.yml'
|
44
46
|
paths << '.youplotrc'
|
45
|
-
|
46
|
-
|
47
|
+
if ENV['HOME']
|
48
|
+
paths << File.join(ENV['HOME'], '.youplotrc')
|
49
|
+
paths << File.join(ENV['HOME'], '.youplot.yml')
|
50
|
+
paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplotrc')
|
51
|
+
paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplot.yml')
|
52
|
+
end
|
47
53
|
paths
|
48
54
|
end
|
49
55
|
|
50
56
|
def find_config_file
|
51
|
-
|
52
|
-
candidate_paths.each do |file|
|
57
|
+
config_file_candidate_paths.each do |file|
|
53
58
|
path = File.expand_path(file)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
next unless File.exist?(path)
|
60
|
+
|
61
|
+
@config_file = path
|
62
|
+
ENV['MYYOUPLOTRC'] = path
|
63
|
+
return @config_file
|
58
64
|
end
|
59
|
-
|
65
|
+
nil
|
60
66
|
end
|
61
67
|
|
62
|
-
def read_config_file
|
68
|
+
def read_config_file
|
63
69
|
require 'yaml'
|
64
|
-
YAML.load_file(
|
70
|
+
@config = YAML.load_file(config_file)
|
65
71
|
end
|
66
72
|
|
67
|
-
def configure
|
73
|
+
def configure
|
68
74
|
option_members = @options.members
|
69
75
|
param_members = @params.members
|
70
76
|
# It would be more useful to be able to configure by plot type
|
71
77
|
config.each do |k, v|
|
72
78
|
k = k.to_sym
|
73
79
|
if option_members.include?(k)
|
74
|
-
@options[k]
|
80
|
+
@options[k] ||= v
|
75
81
|
elsif param_members.include?(k)
|
76
|
-
@params[k]
|
82
|
+
@params[k] ||= v
|
77
83
|
else
|
78
|
-
raise Error, "Unknown option/param: #{k}"
|
84
|
+
raise Error, "Unknown option/param in config file: #{k}"
|
79
85
|
end
|
80
86
|
end
|
81
87
|
end
|
@@ -154,6 +160,9 @@ module YouPlot
|
|
154
160
|
puts parser.help
|
155
161
|
exit if YouPlot.run_as_executable?
|
156
162
|
end
|
163
|
+
parser.on('--config FILE', 'specify a config file') do |v|
|
164
|
+
@config_file = v
|
165
|
+
end
|
157
166
|
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
158
167
|
options[:debug] = v
|
159
168
|
end
|
@@ -185,6 +194,7 @@ module YouPlot
|
|
185
194
|
colors color show the list of available colors
|
186
195
|
|
187
196
|
General options:
|
197
|
+
--config print config file info
|
188
198
|
--help print command specific help menu
|
189
199
|
--version print the version of YouPlot
|
190
200
|
MSG
|
@@ -192,10 +202,36 @@ module YouPlot
|
|
192
202
|
# Help for the main parser is simple.
|
193
203
|
# Simply show the banner above.
|
194
204
|
main_parser.on('--help', 'print sub-command help menu') do
|
195
|
-
|
196
|
-
puts
|
197
|
-
exit if YouPlot.run_as_executable?
|
205
|
+
show_main_help
|
198
206
|
end
|
207
|
+
|
208
|
+
main_parser.on('--config', 'show config file info') do
|
209
|
+
show_config_info
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def show_main_help(out = $stdout)
|
214
|
+
out.puts main_parser.banner
|
215
|
+
out.puts
|
216
|
+
exit if YouPlot.run_as_executable?
|
217
|
+
end
|
218
|
+
|
219
|
+
def show_config_info
|
220
|
+
if ENV['MYYOUPLOTRC']
|
221
|
+
puts "config file : #{ENV['MYYOUPLOTRC']}"
|
222
|
+
puts config.inspect
|
223
|
+
else
|
224
|
+
puts <<~EOS
|
225
|
+
Configuration file not found.
|
226
|
+
It should be a YAML file, like this example:
|
227
|
+
width : 40
|
228
|
+
height : 20
|
229
|
+
By default, YouPlot will look for the configuration file in these locations:
|
230
|
+
#{config_file_candidate_paths.map { |s| ' ' + s }.join("\n")}
|
231
|
+
If you have the file elsewhere, you can specify its location with the `MYYOUPLOTRC` environment variable.
|
232
|
+
EOS
|
233
|
+
end
|
234
|
+
exit if YouPlot.run_as_executable?
|
199
235
|
end
|
200
236
|
|
201
237
|
def sub_parser_add_symbol
|
@@ -265,10 +301,13 @@ module YouPlot
|
|
265
301
|
case command
|
266
302
|
|
267
303
|
# If you type only `uplot` in the terminal.
|
304
|
+
# Output help to standard error output.
|
268
305
|
when nil
|
269
|
-
|
270
|
-
|
271
|
-
|
306
|
+
show_main_help($stderr)
|
307
|
+
|
308
|
+
# Output help to standard output.
|
309
|
+
when :help
|
310
|
+
show_main_help
|
272
311
|
|
273
312
|
when :barplot, :bar
|
274
313
|
sub_parser_add_symbol
|
@@ -291,14 +330,14 @@ module YouPlot
|
|
291
330
|
params.nbins = v
|
292
331
|
end
|
293
332
|
|
294
|
-
when :lineplot, :line
|
333
|
+
when :lineplot, :line, :l
|
295
334
|
sub_parser_add_canvas
|
296
335
|
sub_parser_add_grid
|
297
336
|
sub_parser_add_fmt_yx
|
298
337
|
sub_parser_add_ylim
|
299
338
|
sub_parser_add_xlim
|
300
339
|
|
301
|
-
when :lineplots, :lines
|
340
|
+
when :lineplots, :lines, :ls
|
302
341
|
sub_parser_add_canvas
|
303
342
|
sub_parser_add_grid
|
304
343
|
sub_parser_add_fmt_xyxy
|
@@ -327,16 +366,19 @@ module YouPlot
|
|
327
366
|
options[:color_names] = v
|
328
367
|
end
|
329
368
|
|
369
|
+
# Currently it simply displays the configuration file,
|
370
|
+
# but in the future this may be changed to open a text editor like Vim
|
371
|
+
# to edit the configuration file.
|
330
372
|
when :config
|
373
|
+
show_config_info
|
331
374
|
|
332
375
|
else
|
333
|
-
error_message = "
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
end
|
376
|
+
error_message = "YouPlot: unrecognized command '#{command}'"
|
377
|
+
raise Error, error_message unless YouPlot.run_as_executable?
|
378
|
+
|
379
|
+
warn error_message
|
380
|
+
exit 1
|
381
|
+
|
340
382
|
end
|
341
383
|
end
|
342
384
|
|
@@ -344,7 +386,7 @@ module YouPlot
|
|
344
386
|
begin
|
345
387
|
create_main_parser.order!(argv)
|
346
388
|
rescue OptionParser::ParseError => e
|
347
|
-
warn "
|
389
|
+
warn "YouPlot: #{e.message}"
|
348
390
|
exit 1 if YouPlot.run_as_executable?
|
349
391
|
end
|
350
392
|
|
@@ -353,7 +395,14 @@ module YouPlot
|
|
353
395
|
begin
|
354
396
|
create_sub_parser&.parse!(argv)
|
355
397
|
rescue OptionParser::ParseError => e
|
356
|
-
warn "
|
398
|
+
warn "YouPlot: #{e.message}"
|
399
|
+
exit 1 if YouPlot.run_as_executable?
|
400
|
+
end
|
401
|
+
|
402
|
+
begin
|
403
|
+
apply_config_file
|
404
|
+
rescue StandardError => e
|
405
|
+
warn "YouPlot: #{e.message}"
|
357
406
|
exit 1 if YouPlot.run_as_executable?
|
358
407
|
end
|
359
408
|
end
|
data/lib/youplot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_plot
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.4.1
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: A command line tool for Unicode Plotting
|