youplot 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a924bdaf315e9b7b8afa65d0f02cdbb22c213fbf80908e2ae30d12d1bc3d9338
4
- data.tar.gz: ea42f957954e37d8d1f4eaf3c789e52188f96aff1afbf99dae6179be14ab06d5
3
+ metadata.gz: 725b5bffb6d597af728d9b57aedea75dbdf62182ab5c211c4ecdca35b686cb69
4
+ data.tar.gz: 7eb1d48b2ba900f9955b0cb257f95d79646101598b86d841951b3271b55e0d2b
5
5
  SHA512:
6
- metadata.gz: 602975a225b979ad6ca2a43ef038f18a23b48f034ddb2a06ffa3f4ca0d61cb805e6ef314afd00a897f8bc869fcce8b27fee895ac6e0f3f82bc7cbe8531369632
7
- data.tar.gz: 0d9f77815d3c2e7f338dfe42f0b501a51dd9dd3de06cc367a7ee3de52e049a6a7e55ee3afc4cc2a525a724b07412f5807feba3c9aea33966d407d38d96fb8601
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)
@@ -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])
@@ -29,53 +29,59 @@ module YouPlot
29
29
  )
30
30
 
31
31
  @params = Parameters.new
32
+ end
32
33
 
33
- if @config_file = find_config_file
34
- ENV['MYYOUPLOTRC'] = @config_file
35
- @config = read_config_file(config_file)
36
- configure(config)
37
- end
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 candidate_paths
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
- paths << File.join(ENV['HOME'], '.youplotrc') if ENV['HOME']
46
- paths << File.join(ENV['HOME'], '.youplot.yml') if ENV['HOME']
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
- config_file_path = nil
52
- candidate_paths.each do |file|
57
+ config_file_candidate_paths.each do |file|
53
58
  path = File.expand_path(file)
54
- if File.exist?(path)
55
- config_file_path = path
56
- break
57
- end
59
+ next unless File.exist?(path)
60
+
61
+ @config_file = path
62
+ ENV['MYYOUPLOTRC'] = path
63
+ return @config_file
58
64
  end
59
- config_file_path
65
+ nil
60
66
  end
61
67
 
62
- def read_config_file(path)
68
+ def read_config_file
63
69
  require 'yaml'
64
- YAML.load_file(path)
70
+ @config = YAML.load_file(config_file)
65
71
  end
66
72
 
67
- def configure(config)
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] = v
80
+ @options[k] ||= v
75
81
  elsif param_members.include?(k)
76
- @params[k] = v
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
- puts main_parser.banner
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
- warn main_parser.banner
270
- warn "\n"
271
- exit 1 if YouPlot.run_as_executable?
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 = "uplot: unrecognized command '#{command}'"
334
- if YouPlot.run_as_executable?
335
- warn error_message
336
- exit 1
337
- else
338
- raise Error, error_message
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 "uplot: #{e.message}"
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 "uplot: #{e.message}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouPlot
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.5'
5
5
  end
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
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: 2022-08-02 00:00:00.000000000 Z
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.3.7
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