whatoption 0.1.0 → 0.2.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/whatoption +4 -0
  3. data/lib/whatoption.rb +25 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dceb90256c82b20eb0838c98b9aa75ed1747662d93b96232e20164e1279d3ff
4
- data.tar.gz: 8a4c446c1961099ce494e2c669154d3bbc8d8c80294e4bc179ae6ae619f7d1fb
3
+ metadata.gz: eba18bf18642b07d11d846b7abbaf16932df2b47ac8a86128243ae5c4a0e5825
4
+ data.tar.gz: 487e4c5d7fb30d871deeefcf04f80b9a6f9d82bc80a8cbd4167b25ab27cfaa77
5
5
  SHA512:
6
- metadata.gz: 5baf5062312181ecb72ffff8ac6aefda961c2f499648d4d94657495ad5febc5cdc427102172b2e29497ff2ee381b30638a18970c5bde608622e0fe0aedb553aa
7
- data.tar.gz: 170829ba3140198e7e7bf711b5275450375258b56dca1c0577b87febd13a1ce811a730c16237094055f8c4f615c2fc32fd4047579bfaf6fc01386e8e32087ec3
6
+ metadata.gz: 0d945a051921d4b807594f203ab8fc96008e3c392126bd841ffab2d3d280016f9d6bb33a7d718c6ae7a6aeb970aba4d56a3c923ca3ee6ba95c2866843c1921c2
7
+ data.tar.gz: 11f2853c227dcb57fd037a28c809ef1325c7a9eb050e02f8eacf5294656c7edccdd482a82e90bb1ab2ff5db182209b8f59e281cafe0402c374a2f8eac4f36ede
data/bin/whatoption CHANGED
@@ -61,6 +61,8 @@ class WhatOption::CliHandler
61
61
 
62
62
  # routine
63
63
  def help
64
+ puts("WhatOption v#{WhatOption::VERSION}")
65
+ puts
64
66
  puts <<~HELP
65
67
  Usage:
66
68
 
@@ -77,6 +79,8 @@ class WhatOption::CliHandler
77
79
  whatoption ruby -c
78
80
  whatoption tar x
79
81
  whatoption git ls-files -z
82
+ whatoption bash -c
83
+ whatoption bash [ -n
80
84
 
81
85
  HELP
82
86
  end
data/lib/whatoption.rb CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  module WhatOption
19
19
 
20
- VERSION = "0.1.0"
20
+ VERSION = "0.2.0"
21
21
 
22
22
  require 'pathname'
23
23
  OPTIONS_DATA_DIR = Pathname.new File.expand_path("~/.whatoption")
@@ -42,8 +42,9 @@ module WhatOption
42
42
 
43
43
  @file # the target TOML file we will load in
44
44
 
45
- @rec_option # record field in toml file
46
- @rec_desc # record field in toml file
45
+ @rec_usage # record field: the option's usage
46
+ @rec_desc # record field: the option's own meaning
47
+ @rec_func # record field: the function of the option
47
48
 
48
49
  =end
49
50
 
@@ -63,14 +64,25 @@ module WhatOption
63
64
 
64
65
  # routine
65
66
  def load_sheet
67
+ require 'tomlrb'
66
68
  # It's very interesting here, you have to put parentheses then 'commands.join()' is
67
69
  # treated as a string.
68
70
  # Without parentheses, the + is affected by OPTIONS_DATA_DIR,
69
71
  # So first '+'s both side are Pathname
70
72
  # And '+' is to add a '/' to component
71
73
  @file = OPTIONS_DATA_DIR + (@commands.join('/') + ".toml")
74
+
75
+ # if the file not exists, it is maybe in the dir (with its own name)
76
+ # For example:
77
+ # "bash -c" will first search 'ROOT/bash.toml'
78
+ # if not exist, then we will search 'ROOT/bash/bash.toml'
79
+ #
80
+ if ! File.exist? @file
81
+ @file = Pathname.new(@file.to_s.delete_suffix(".toml")) +
82
+ (@commands.last + ".toml")
83
+ end
84
+
72
85
  if File.exist? @file
73
- require 'tomlrb'
74
86
  return Tomlrb.load_file @file
75
87
  else
76
88
  puts "File #@file not exist!"
@@ -89,12 +101,15 @@ module WhatOption
89
101
  record = sheet[@option] ||
90
102
  puts("Error: Option [#@option] is not recorded in #@file".red) ||
91
103
  exit(1)
92
- @rec_option = record['option'] ||
93
- puts("Error: No field 'option' in #@file [#@calling_command]".red) ||
104
+ @rec_usage = record['usage'] ||
105
+ puts("Error: No field 'usage' in #@file [#@calling_command]".red) ||
94
106
  exit(1)
95
107
  @rec_desc = record['desc'] ||
96
108
  puts("Error: No field 'desc' in #@file [#@calling_command]".red) ||
97
109
  exit(1)
110
+ @rec_func = record['func'] ||
111
+ puts("Error: No field 'func' in #@file [#@calling_command]".red) ||
112
+ exit(1)
98
113
  end
99
114
 
100
115
 
@@ -106,12 +121,14 @@ module WhatOption
106
121
  if not @sub_commands.empty?
107
122
  result_cmd += ' ' + @sub_commands.join(' ').blue
108
123
  end
109
- result_cmd += ' ' + @rec_option.magenta
124
+ result_cmd += ' ' + @rec_usage.magenta
110
125
  puts result_cmd
111
126
 
112
127
  # newline description
113
- print "\n "
128
+ print "\n #{@option}: "
114
129
  puts @rec_desc.green
130
+ print "\n "
131
+ puts @rec_func
115
132
  puts
116
133
  end
117
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatoption
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ccmywish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb