whatoption 0.2.0 → 0.3.1
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 +45 -25
- data/lib/whatoption.rb +25 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c63a49419c51f74f67a91a8f064182e0edad18ea31db1ed86a17cc0022eda091
|
4
|
+
data.tar.gz: 840b7599e54ea02c20357e8d653ec6c4ba04aa7c0743983c74ddcec73e45dfb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5753baf60b7353155c9154495a33c33f10403556f2e73968d650a8fff657e61c25dda3ebb1163491f6d48fa36c5c0c02efc6766fe06c85e6589712df5a4effa
|
7
|
+
data.tar.gz: 4468ab208fcc6e0bd24d13307b9f58fcb1939d4ac39b3566c48767aed093dd79958fada73160149fd59ba3e454cf81633c478fe83d898c66d6df938bbf04d3e6
|
data/bin/whatoption
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# ---------------------------------------------------------------
|
3
3
|
# File : whatoption.rb
|
4
|
-
# Authors :
|
4
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
5
5
|
# Created on : <2023-02-06>
|
6
|
-
# Last modified : <2023-
|
6
|
+
# Last modified : <2023-03-14>
|
7
7
|
# Contributors :
|
8
8
|
#
|
9
9
|
# whatoption:
|
10
10
|
#
|
11
11
|
# Tells you what the option of the command means.
|
12
12
|
#
|
13
|
-
# ----------
|
14
|
-
# Changelog:
|
15
|
-
#
|
16
|
-
# ~> v0.1.0
|
17
|
-
# <2023-02-06> Create file
|
18
13
|
# ---------------------------------------------------------------
|
19
14
|
|
20
15
|
require 'whatoption'
|
@@ -26,6 +21,9 @@ require 'whatoption'
|
|
26
21
|
class WhatOption::CliHandler
|
27
22
|
|
28
23
|
def initialize(argv)
|
24
|
+
|
25
|
+
@argv = argv
|
26
|
+
|
29
27
|
if argv.empty?
|
30
28
|
help || return
|
31
29
|
end
|
@@ -43,18 +41,12 @@ class WhatOption::CliHandler
|
|
43
41
|
puts cmd = "git -C #{WhatOption::OPTIONS_DATA_DIR} pull"
|
44
42
|
system cmd
|
45
43
|
return
|
44
|
+
when '-l'
|
45
|
+
list_options
|
46
|
+
else
|
47
|
+
get_option
|
46
48
|
end
|
47
49
|
|
48
|
-
if argv.size == 1
|
49
|
-
puts("Please input the option for command '#{argv[0]}'".red) || return
|
50
|
-
end
|
51
|
-
|
52
|
-
@option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
|
53
|
-
# because some options are just single characters,
|
54
|
-
# for example, 'tar x', this is to use subcommand as option
|
55
|
-
# That's reasonable also.
|
56
|
-
@commands = ARGV[0...-1]
|
57
|
-
|
58
50
|
# p option
|
59
51
|
# p commands
|
60
52
|
end
|
@@ -70,9 +62,10 @@ class WhatOption::CliHandler
|
|
70
62
|
|
71
63
|
Options:
|
72
64
|
|
73
|
-
-u
|
74
|
-
-
|
75
|
-
-
|
65
|
+
-u Update ~/.whatoption data
|
66
|
+
-l <command> List command options
|
67
|
+
-h Print this help
|
68
|
+
-v Print version
|
76
69
|
|
77
70
|
Examples:
|
78
71
|
|
@@ -85,17 +78,44 @@ class WhatOption::CliHandler
|
|
85
78
|
HELP
|
86
79
|
end
|
87
80
|
|
88
|
-
|
89
|
-
|
81
|
+
|
82
|
+
# routine
|
83
|
+
def get_option
|
84
|
+
|
85
|
+
if @argv.size == 1
|
86
|
+
puts("Please input the option for command '#{@argv[0]}'".red) || return
|
87
|
+
end
|
88
|
+
|
89
|
+
option = ARGV[-1] # Shouldn't detect where is begin with '-' or '--'
|
90
|
+
# because some options are just single characters,
|
91
|
+
# for example, 'tar x', this is to use subcommand as option
|
92
|
+
# That's reasonable also.
|
93
|
+
commands = ARGV[0...-1]
|
94
|
+
|
90
95
|
# Because the initializer above will not always finish initializing
|
91
|
-
if (not
|
96
|
+
if (not commands) || (not option)
|
92
97
|
exit
|
93
98
|
end
|
94
|
-
option_info = WhatOption::OptionInfo.new
|
99
|
+
option_info = WhatOption::OptionInfo.new commands, option
|
95
100
|
option_info.show
|
96
101
|
end
|
97
102
|
|
103
|
+
|
104
|
+
# routine
|
105
|
+
def list_options
|
106
|
+
|
107
|
+
if @argv.size == 1
|
108
|
+
puts("Please input the command name after '-l'".red) || return
|
109
|
+
end
|
110
|
+
|
111
|
+
option = nil
|
112
|
+
commands = ARGV[1..-1]
|
113
|
+
option_info = WhatOption::OptionInfo.new commands, option
|
114
|
+
option_info.list
|
115
|
+
end
|
116
|
+
|
117
|
+
|
98
118
|
end
|
99
119
|
|
120
|
+
# main
|
100
121
|
cli = WhatOption::CliHandler.new ARGV
|
101
|
-
cli.work
|
data/lib/whatoption.rb
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
# ---------------------------------------------------------------
|
2
2
|
# File : whatoption.rb
|
3
|
-
# Authors :
|
3
|
+
# Authors : Aoran Zeng <ccmywish@qq.com>
|
4
4
|
# Created on : <2023-02-06>
|
5
|
-
# Last modified : <2023-
|
5
|
+
# Last modified : <2023-03-14>
|
6
6
|
#
|
7
7
|
# whatoption:
|
8
8
|
#
|
9
9
|
# Lib file
|
10
10
|
#
|
11
|
-
# ----------
|
12
|
-
# Changelog:
|
13
|
-
#
|
14
|
-
# ~> v0.1.0
|
15
|
-
# <2023-02-06> Create file
|
16
11
|
# ---------------------------------------------------------------
|
17
12
|
|
18
13
|
module WhatOption
|
19
14
|
|
20
|
-
VERSION = "0.
|
15
|
+
VERSION = "0.3.1"
|
21
16
|
|
22
17
|
require 'pathname'
|
23
18
|
OPTIONS_DATA_DIR = Pathname.new File.expand_path("~/.whatoption")
|
@@ -91,6 +86,28 @@ module WhatOption
|
|
91
86
|
end
|
92
87
|
|
93
88
|
|
89
|
+
# method
|
90
|
+
def list
|
91
|
+
sheet = load_sheet
|
92
|
+
if not sheet
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
option_max_len = sheet.keys.map(&:length).max
|
97
|
+
left = option_max_len + 3
|
98
|
+
|
99
|
+
lmda = -> hash do hash['desc'].length end
|
100
|
+
desc_max_len = sheet.values.map(&lmda).max
|
101
|
+
|
102
|
+
middle = desc_max_len + 3
|
103
|
+
|
104
|
+
puts "Options for '#{@commands.join}':"
|
105
|
+
sheet.each do |key, value|
|
106
|
+
printf " %s%s%s\n", key.ljust(left), value['desc'].ljust(middle), value['func']
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
94
111
|
# routine
|
95
112
|
def resolve
|
96
113
|
sheet = load_sheet
|
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.
|
4
|
+
version: 0.3.1
|
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-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|