cliapp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +131 -0
- data/Rakefile.rb +9 -0
- data/cliapp.gemspec +29 -0
- data/lib/cliapp.rb +430 -0
- data/task/common-task.rb +67 -0
- data/task/release-task.rb +77 -0
- data/test/action_test.rb +54 -0
- data/test/application_test.rb +547 -0
- data/test/init.rb +11 -0
- data/test/module_test.rb +92 -0
- data/test/util_test.rb +80 -0
- metadata +74 -0
data/test/module_test.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
require_relative './init'
|
6
|
+
|
7
|
+
|
8
|
+
Oktest.scope do
|
9
|
+
|
10
|
+
|
11
|
+
topic CLIApp do
|
12
|
+
|
13
|
+
|
14
|
+
topic '.new()' do
|
15
|
+
|
16
|
+
fixture :app do
|
17
|
+
CLIApp.new("Sample", "Sample App", command: "sample", version: "1.2.3")
|
18
|
+
end
|
19
|
+
|
20
|
+
spec "[!gpvqe] creates new Config object internally." do
|
21
|
+
|app|
|
22
|
+
ok {app.config.name} == "Sample"
|
23
|
+
ok {app.config.desc} == "Sample App"
|
24
|
+
ok {app.config.command} == "sample"
|
25
|
+
ok {app.config.version} == "1.2.3"
|
26
|
+
end
|
27
|
+
|
28
|
+
spec "[!qyunk] creates new Application object with config object created." do
|
29
|
+
|app|
|
30
|
+
ok {app}.is_a?(CLIApp::Application)
|
31
|
+
ok {app.config}.is_a?(CLIApp::Config)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
topic '.skeleton()' do
|
38
|
+
|
39
|
+
GLOBAL_HELP = <<'END'
|
40
|
+
Sample (1.0.0) --- Sample Application
|
41
|
+
|
42
|
+
Usage:
|
43
|
+
$ tmp.sample [<options>] <action> [<arguments>...]
|
44
|
+
|
45
|
+
Options:
|
46
|
+
-h, --help print help message
|
47
|
+
--version print version number
|
48
|
+
-l, --list list action names
|
49
|
+
|
50
|
+
Actions:
|
51
|
+
clean delete garbage files (& product files too if '-a')
|
52
|
+
hello greeting message
|
53
|
+
END
|
54
|
+
|
55
|
+
HELLO_HELP = <<'END'
|
56
|
+
tmp.sample hello --- greeting message
|
57
|
+
|
58
|
+
Usage:
|
59
|
+
$ tmp.sample hello [<options>] [<name>]
|
60
|
+
|
61
|
+
Options:
|
62
|
+
-l, --lang=<en|fr|it> language
|
63
|
+
END
|
64
|
+
|
65
|
+
spec "[!zls9g] returns example code." do
|
66
|
+
str = CLIApp.skeleton()
|
67
|
+
ok {str}.is_a?(String)
|
68
|
+
filename = "tmp.sample"
|
69
|
+
dummy_file(filename, str)
|
70
|
+
#
|
71
|
+
sout, serr = capture_command "ruby #{filename} --help"
|
72
|
+
ok {serr} == ""
|
73
|
+
ok {sout} == GLOBAL_HELP
|
74
|
+
#
|
75
|
+
sout, serr = capture_command "ruby #{filename} hello --help"
|
76
|
+
ok {serr} == ""
|
77
|
+
ok {sout} == HELLO_HELP
|
78
|
+
#
|
79
|
+
sout, serr = capture_command "ruby #{filename} hello"
|
80
|
+
ok {serr} == ""
|
81
|
+
ok {sout} == "Hello, world!\n"
|
82
|
+
sout, serr = capture_command "ruby #{filename} hello Alice --lang=fr"
|
83
|
+
ok {serr} == ""
|
84
|
+
ok {sout} == "Bonjour, Alice!\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
end
|
data/test/util_test.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
require_relative './init'
|
6
|
+
|
7
|
+
|
8
|
+
Oktest.scope do
|
9
|
+
|
10
|
+
|
11
|
+
topic CLIApp::Util do
|
12
|
+
|
13
|
+
|
14
|
+
topic '#arity_of_proc()' do
|
15
|
+
|
16
|
+
spec "[!get6i] returns min and max arity of proc object." do
|
17
|
+
pr1 = proc {|a, b, c=nil, d=nil, x: nil, y: nil| nil }
|
18
|
+
ok {CLIApp::Util.arity_of_proc(pr1)} == [2, 4]
|
19
|
+
pr2 = proc {|a=nil, b=nil| nil }
|
20
|
+
ok {CLIApp::Util.arity_of_proc(pr2)} == [0, 2]
|
21
|
+
pr3 = proc { nil }
|
22
|
+
ok {CLIApp::Util.arity_of_proc(pr3)} == [0, 0]
|
23
|
+
end
|
24
|
+
|
25
|
+
spec "[!ghrxo] returns nil as max arity if proc has variable param." do
|
26
|
+
pr1 = proc {|a, b, c=nil, d=nil, *e, x: nil, y: nil| nil }
|
27
|
+
ok {CLIApp::Util.arity_of_proc(pr1)} == [2, nil]
|
28
|
+
pr2 = proc {|a=nil, b=nil, *c| nil }
|
29
|
+
ok {CLIApp::Util.arity_of_proc(pr2)} == [0, nil]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
topic '#argstr_of_proc()' do
|
36
|
+
|
37
|
+
spec "[!gbk7b] generates argument string of proc object." do
|
38
|
+
pr1 = proc {|aa, bb, cc=nil, dd=nil, x: nil, y: nil| nil }
|
39
|
+
ok {CLIApp::Util.argstr_of_proc(pr1)} == " <aa> <bb> [<cc> [<dd>]]"
|
40
|
+
end
|
41
|
+
|
42
|
+
spec "[!b6gzp] required param should be '<param>'." do
|
43
|
+
pr1 = proc {|aa, bb| nil }
|
44
|
+
ok {CLIApp::Util.argstr_of_proc(pr1)} == " <aa> <bb>"
|
45
|
+
end
|
46
|
+
|
47
|
+
spec "[!q1030] optional param should be '[<param>]'." do
|
48
|
+
pr1 = proc {|aa=nil, bb=nil| nil }
|
49
|
+
ok {CLIApp::Util.argstr_of_proc(pr1)} == " [<aa> [<bb>]]"
|
50
|
+
end
|
51
|
+
|
52
|
+
spec "[!osxwq] variable param should be '[<param>...]'." do
|
53
|
+
pr1 = proc {|aa, bb=nil, *cc| nil }
|
54
|
+
ok {CLIApp::Util.argstr_of_proc(pr1)} == " <aa> [<bb> [<cc>...]]"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
topic '#param2argname()' do
|
61
|
+
|
62
|
+
spec "[!52dzl] converts 'yes_or_no' to 'yes|no'." do
|
63
|
+
ok {CLIApp::Util.param2argname("yes_or_no")} == "yes|no"
|
64
|
+
end
|
65
|
+
|
66
|
+
spec "[!6qkk6] converts 'file__html' to 'file.html'." do
|
67
|
+
ok {CLIApp::Util.param2argname("file__html")} == "file.html"
|
68
|
+
end
|
69
|
+
|
70
|
+
spec "[!2kbhe] converts 'aa_bb_cc' to 'aa-bb-cc'." do
|
71
|
+
ok {CLIApp::Util.param2argname("aa_bb_cc")} == "aa-bb-cc"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cliapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kwatch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oktest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
description: 'A small framework for CLI Applications such as Git, Docker, NPM, etc.
|
28
|
+
|
29
|
+
'
|
30
|
+
email: kwatch@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile.rb
|
38
|
+
- cliapp.gemspec
|
39
|
+
- lib/cliapp.rb
|
40
|
+
- task/common-task.rb
|
41
|
+
- task/release-task.rb
|
42
|
+
- test/action_test.rb
|
43
|
+
- test/application_test.rb
|
44
|
+
- test/init.rb
|
45
|
+
- test/module_test.rb
|
46
|
+
- test/util_test.rb
|
47
|
+
homepage: https://github.com/kwatch/cliapp-ruby
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.4'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.0.3.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: CLI Application Framework
|
70
|
+
test_files:
|
71
|
+
- test/module_test.rb
|
72
|
+
- test/util_test.rb
|
73
|
+
- test/action_test.rb
|
74
|
+
- test/application_test.rb
|