whatoption 0.3.1 → 0.3.2
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/bin/whatoption +20 -24
- data/lib/whatoption.rb +22 -27
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 848dbf43f6c817383346a8e3be861eaadf2830b2fd42d452b95d25593622edb2
|
4
|
+
data.tar.gz: e367a5e0e18f28c13b9069c1dc1b80066ffa22d4444c4ec33e51d67facebdc2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dcfe42d91f55d6ae8b5b4e5916fe796765cbdf5c3f81c35e47210b62dd365cc7a7ee2531385917378aed0e00de18c78f8653af87d33a8d2f49a8131d1d5db03
|
7
|
+
data.tar.gz: af43594ab72b173b25887aab3cf8d5c5717fd7ed3dcdb5377d7b5f7476a5c4978327b0897d5c6da7499ebcde3da9cd1c78d5b784c1727386f71d313e0d2d1122
|
data/bin/whatoption
CHANGED
@@ -3,24 +3,28 @@
|
|
3
3
|
# File : whatoption.rb
|
4
4
|
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
5
|
# Created on : <2023-02-06>
|
6
|
-
# Last modified : <2023-
|
6
|
+
# Last modified : <2023-07-29>
|
7
7
|
# Contributors :
|
8
8
|
#
|
9
9
|
# whatoption:
|
10
10
|
#
|
11
11
|
# Tells you what the option of the command means.
|
12
|
-
#
|
13
12
|
# ---------------------------------------------------------------
|
14
13
|
|
15
14
|
require 'whatoption'
|
16
15
|
|
16
|
+
require 'rainbow/refinement'
|
17
|
+
using Rainbow
|
18
|
+
|
17
19
|
####################
|
18
20
|
# main
|
19
21
|
####################
|
20
22
|
|
21
|
-
class WhatOption::
|
23
|
+
class WhatOption::CLI
|
22
24
|
|
23
|
-
def
|
25
|
+
def self.run
|
26
|
+
|
27
|
+
argv = ARGV.dup
|
24
28
|
|
25
29
|
@argv = argv
|
26
30
|
|
@@ -41,8 +45,6 @@ class WhatOption::CliHandler
|
|
41
45
|
puts cmd = "git -C #{WhatOption::OPTIONS_DATA_DIR} pull"
|
42
46
|
system cmd
|
43
47
|
return
|
44
|
-
when '-l'
|
45
|
-
list_options
|
46
48
|
else
|
47
49
|
get_option
|
48
50
|
end
|
@@ -51,24 +53,24 @@ class WhatOption::CliHandler
|
|
51
53
|
# p commands
|
52
54
|
end
|
53
55
|
|
54
|
-
|
55
|
-
def help
|
56
|
+
|
57
|
+
def self.help
|
56
58
|
puts("WhatOption v#{WhatOption::VERSION}")
|
57
59
|
puts
|
58
60
|
puts <<~HELP
|
59
61
|
Usage:
|
60
62
|
|
61
|
-
whatoption command subcommands option
|
63
|
+
whatoption <command> [subcommands] <option>
|
62
64
|
|
63
|
-
|
65
|
+
Switches:
|
64
66
|
|
65
|
-
-u Update
|
66
|
-
-l <command> List command options
|
67
|
+
-u Update options data
|
67
68
|
-h Print this help
|
68
69
|
-v Print version
|
69
70
|
|
70
71
|
Examples:
|
71
72
|
|
73
|
+
whatoption rpm
|
72
74
|
whatoption ruby -c
|
73
75
|
whatoption tar x
|
74
76
|
whatoption git ls-files -z
|
@@ -79,11 +81,11 @@ class WhatOption::CliHandler
|
|
79
81
|
end
|
80
82
|
|
81
83
|
|
82
|
-
|
83
|
-
def get_option
|
84
|
+
def self.get_option
|
84
85
|
|
85
86
|
if @argv.size == 1
|
86
|
-
puts("Please input the option for command '#{@argv[0]}'".red) || return
|
87
|
+
# puts("Please input the option for command '#{@argv[0]}'".red) || return
|
88
|
+
return list_options
|
87
89
|
end
|
88
90
|
|
89
91
|
option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
|
@@ -101,15 +103,9 @@ class WhatOption::CliHandler
|
|
101
103
|
end
|
102
104
|
|
103
105
|
|
104
|
-
|
105
|
-
def list_options
|
106
|
-
|
107
|
-
if @argv.size == 1
|
108
|
-
puts("Please input the command name after '-l'".red) || return
|
109
|
-
end
|
110
|
-
|
106
|
+
def self.list_options
|
111
107
|
option = nil
|
112
|
-
commands = ARGV[
|
108
|
+
commands = [ARGV[0]]
|
113
109
|
option_info = WhatOption::OptionInfo.new commands, option
|
114
110
|
option_info.list
|
115
111
|
end
|
@@ -118,4 +114,4 @@ class WhatOption::CliHandler
|
|
118
114
|
end
|
119
115
|
|
120
116
|
# main
|
121
|
-
|
117
|
+
WhatOption::CLI.run
|
data/lib/whatoption.rb
CHANGED
@@ -2,30 +2,32 @@
|
|
2
2
|
# File : whatoption.rb
|
3
3
|
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
4
|
# Created on : <2023-02-06>
|
5
|
-
# Last modified : <2023-
|
5
|
+
# Last modified : <2023-07-29>
|
6
6
|
#
|
7
7
|
# whatoption:
|
8
8
|
#
|
9
9
|
# Lib file
|
10
|
-
#
|
11
10
|
# ---------------------------------------------------------------
|
12
11
|
|
12
|
+
require 'rainbow/refinement'
|
13
|
+
using Rainbow
|
14
|
+
|
13
15
|
module WhatOption
|
14
16
|
|
15
|
-
VERSION = "0.3.
|
17
|
+
VERSION = "0.3.2"
|
16
18
|
|
19
|
+
require 'standard_path'
|
17
20
|
require 'pathname'
|
18
|
-
OPTIONS_DATA_DIR = Pathname.new File.expand_path("~/.whatoption")
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
WhatOption_DATA_DIR = Pathname.new StandardPath.app_data 'WhatOption'
|
23
|
+
|
24
|
+
if not Dir.exist? WhatOption_DATA_DIR
|
25
|
+
`git clone https://github.com/ccmywish/WhatOptionData #{WhatOption_DATA_DIR}`
|
22
26
|
end
|
23
27
|
|
24
28
|
|
25
29
|
class OptionInfo
|
26
30
|
|
27
|
-
require 'colorator'
|
28
|
-
|
29
31
|
=begin
|
30
32
|
|
31
33
|
attribute:
|
@@ -62,10 +64,10 @@ module WhatOption
|
|
62
64
|
require 'tomlrb'
|
63
65
|
# It's very interesting here, you have to put parentheses then 'commands.join()' is
|
64
66
|
# treated as a string.
|
65
|
-
# Without parentheses, the + is affected by
|
67
|
+
# Without parentheses, the + is affected by WhatOption_DATA_DIR,
|
66
68
|
# So first '+'s both side are Pathname
|
67
69
|
# And '+' is to add a '/' to component
|
68
|
-
@file =
|
70
|
+
@file = WhatOption_DATA_DIR + (@commands.join('/') + ".toml")
|
69
71
|
|
70
72
|
# if the file not exists, it is maybe in the dir (with its own name)
|
71
73
|
# For example:
|
@@ -89,9 +91,7 @@ module WhatOption
|
|
89
91
|
# method
|
90
92
|
def list
|
91
93
|
sheet = load_sheet
|
92
|
-
if not sheet
|
93
|
-
exit 1
|
94
|
-
end
|
94
|
+
abort if not sheet
|
95
95
|
|
96
96
|
option_max_len = sheet.keys.map(&:length).max
|
97
97
|
left = option_max_len + 3
|
@@ -101,9 +101,11 @@ module WhatOption
|
|
101
101
|
|
102
102
|
middle = desc_max_len + 3
|
103
103
|
|
104
|
-
|
104
|
+
print "Options for ", @commands.join.yellow, ":\n"
|
105
105
|
sheet.each do |key, value|
|
106
|
-
printf " %s%s%s\n",
|
106
|
+
printf " %s%s%s\n", key.ljust(left).magenta,
|
107
|
+
value['desc'].ljust(middle).green,
|
108
|
+
value['func']
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
@@ -111,22 +113,16 @@ module WhatOption
|
|
111
113
|
# routine
|
112
114
|
def resolve
|
113
115
|
sheet = load_sheet
|
114
|
-
if not sheet
|
115
|
-
exit 1
|
116
|
-
end
|
116
|
+
abort if not sheet
|
117
117
|
|
118
118
|
record = sheet[@option] ||
|
119
|
-
puts("Error: Option [#@option] is not recorded in #@file".red) ||
|
120
|
-
exit(1)
|
119
|
+
puts("Error: Option [#@option] is not recorded in #@file".red) || abort
|
121
120
|
@rec_usage = record['usage'] ||
|
122
|
-
puts("Error: No field 'usage' in #@file [#@calling_command]".red) ||
|
123
|
-
exit(1)
|
121
|
+
puts("Error: No field 'usage' in #@file [#@calling_command]".red) || abort
|
124
122
|
@rec_desc = record['desc'] ||
|
125
|
-
puts("Error: No field 'desc' in #@file [#@calling_command]".red) ||
|
126
|
-
exit(1)
|
123
|
+
puts("Error: No field 'desc' in #@file [#@calling_command]".red) || abort
|
127
124
|
@rec_func = record['func'] ||
|
128
|
-
puts("Error: No field 'func' in #@file [#@calling_command]".red) ||
|
129
|
-
exit(1)
|
125
|
+
puts("Error: No field 'func' in #@file [#@calling_command]".red) || abort
|
130
126
|
end
|
131
127
|
|
132
128
|
|
@@ -151,5 +147,4 @@ module WhatOption
|
|
151
147
|
|
152
148
|
end
|
153
149
|
|
154
|
-
|
155
150
|
end
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccmywish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|
@@ -25,19 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: standard_path
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rainbow
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
41
55
|
description: 'This command line tool `whatoption` is used to record and explain commands''
|
42
56
|
options, so there is no need to run the command itself to check what the help info
|
43
57
|
is. Besides, many options only have one character, which is sometimes not easily
|
@@ -73,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '0'
|
75
89
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.4.8
|
77
91
|
signing_key:
|
78
92
|
specification_version: 4
|
79
93
|
summary: 'whatoption: What does the option mean?'
|