cli-topic 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clitopic/command/base.rb +6 -3
- data/lib/clitopic/command/clito.rb +6 -5
- data/lib/clitopic/commands.rb +5 -2
- data/lib/clitopic/parser/option_parser.rb +2 -2
- data/lib/clitopic/version.rb +1 -1
- data/lib/clitopic.rb +3 -14
- data/spec/clitopic_spec.rb +30 -0
- data/spec/command/clito_defaults_file_spec.rb +7 -0
- data/spec/command/clito_suggestions_spec.rb +19 -0
- data/spec/command/clito_version_spec.rb +9 -0
- data/spec/command/version_spec.rb +9 -0
- data/spec/spec_helper.rb +2 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8003d6632558c53150f15cf2a82014647761331b
|
4
|
+
data.tar.gz: a677aa796f1db1f45c00b62881994cddd962a90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38947da78454ed0682444d86365dfd6239da094ecccc16badd3381aef6919b54eb8f7f6978d395f0a0dd9d124c16538b0519152951f53b288d319e8ab7e47f9a
|
7
|
+
data.tar.gz: 2bfbbf15f4e7126d190e958eaa8379c30fa42ff0fa79d80dffb4bb8013bd290bd630a0ee714e8324094a7e167929a9ae6f9482ff7bb14fb33035cb83d02ce643
|
@@ -7,8 +7,7 @@ module Clitopic
|
|
7
7
|
module Command
|
8
8
|
class Base
|
9
9
|
class << self
|
10
|
-
include Clitopic
|
11
|
-
|
10
|
+
include Clitopic::Parser::OptParser
|
12
11
|
attr_accessor :name, :banner, :description, :hidden, :short_description
|
13
12
|
attr_accessor :arguments, :options
|
14
13
|
|
@@ -98,11 +97,14 @@ module Clitopic
|
|
98
97
|
begin
|
99
98
|
defaults = YAML.load_file(file)
|
100
99
|
rescue
|
100
|
+
puts "failed to load defaults file: #{file}"
|
101
101
|
return
|
102
102
|
end
|
103
103
|
|
104
104
|
if self.topic.nil?
|
105
|
-
|
105
|
+
if defaults.has_key?("commands")
|
106
|
+
cmd_defaults = defaults["commands"][self.name]
|
107
|
+
end
|
106
108
|
else
|
107
109
|
if defaults.has_key?(self.topic.name)
|
108
110
|
cmd_defaults = defaults[self.topic.name][self.name]
|
@@ -111,6 +113,7 @@ module Clitopic
|
|
111
113
|
end
|
112
114
|
|
113
115
|
if cmd_defaults.nil?
|
116
|
+
puts "no defaults"
|
114
117
|
return
|
115
118
|
end
|
116
119
|
|
@@ -22,7 +22,7 @@ module Clitopic
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
-
class
|
25
|
+
class DefaultsFile < Clitopic::Command::Base
|
26
26
|
register name: 'defaults_file',
|
27
27
|
description: "create default file",
|
28
28
|
hidden: true,
|
@@ -30,7 +30,7 @@ module Clitopic
|
|
30
30
|
|
31
31
|
option :merge, "--[no-]merge", "Merge options with current file", default: true
|
32
32
|
option :force, "-f", "--force", "Overwrite file", default: false
|
33
|
-
|
33
|
+
|
34
34
|
|
35
35
|
class << self
|
36
36
|
def cmd_opts(cmd, opts)
|
@@ -72,7 +72,6 @@ module Clitopic
|
|
72
72
|
raise ArgumentError.new("File #{file} exists, use --merge or --force")
|
73
73
|
end
|
74
74
|
if merge && !force
|
75
|
-
return if not Clitopic::Helpers.confirm("Overwrite #{file} ? (y/N)")
|
76
75
|
opts = opts.merge(YAML.load_file(file))
|
77
76
|
end
|
78
77
|
end
|
@@ -80,7 +79,7 @@ module Clitopic
|
|
80
79
|
File.open(file, 'wb') do |file|
|
81
80
|
file.write(opts.to_yaml)
|
82
81
|
end
|
83
|
-
|
82
|
+
return opts
|
84
83
|
end
|
85
84
|
|
86
85
|
def call
|
@@ -89,7 +88,9 @@ module Clitopic
|
|
89
88
|
raise ArgumentError.new("Missing file")
|
90
89
|
end
|
91
90
|
file = @arguments[0]
|
92
|
-
dump_options(file, @options[:merge], @options[:force])
|
91
|
+
opts = dump_options(file, @options[:merge], @options[:force])
|
92
|
+
puts opts
|
93
|
+
return opts
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
data/lib/clitopic/commands.rb
CHANGED
@@ -79,7 +79,11 @@ module Clitopic
|
|
79
79
|
@current_options, @current_args = cmd.parse(arguments.dup)
|
80
80
|
rescue OptionParser::ParseError => e
|
81
81
|
$stderr.puts Clitopic::Helpers.format_with_bang(e.message)
|
82
|
-
|
82
|
+
cmd.options = {}
|
83
|
+
cmd.arguments = {}
|
84
|
+
@current_options = nil
|
85
|
+
@current_arguments = nil
|
86
|
+
run(cmd.fullname, ["--help"])
|
83
87
|
end
|
84
88
|
|
85
89
|
def run(cmd, arguments=[])
|
@@ -95,7 +99,6 @@ module Clitopic
|
|
95
99
|
end
|
96
100
|
prepare_run(@current_cmd, arguments)
|
97
101
|
if @current_cmd.options[:load_defaults] == true || Clitopic.load_defaults?
|
98
|
-
puts 'load'
|
99
102
|
@current_cmd.load_defaults
|
100
103
|
end
|
101
104
|
@current_cmd.call
|
@@ -56,11 +56,11 @@ module Clitopic
|
|
56
56
|
|
57
57
|
def parse(args)
|
58
58
|
@invalid_options ||= []
|
59
|
-
parser.
|
59
|
+
parser.parse!(args)
|
60
60
|
@arguments = args
|
61
61
|
Clitopic::Commands.validate_arguments!(@invalid_options)
|
62
62
|
return @options, @arguments
|
63
|
-
|
63
|
+
rescue OptionParser::InvalidOption => ex
|
64
64
|
@invalid_options << ex.args.first
|
65
65
|
retry
|
66
66
|
end
|
data/lib/clitopic/version.rb
CHANGED
data/lib/clitopic.rb
CHANGED
@@ -3,26 +3,15 @@ require 'clitopic/parsers'
|
|
3
3
|
|
4
4
|
module Clitopic
|
5
5
|
class << self
|
6
|
-
attr_accessor :debug, :commands_dir, :
|
6
|
+
attr_accessor :debug, :commands_dir, :version, :default_files, :load_defaults, :name
|
7
7
|
def name
|
8
8
|
@name ||= 'clito'
|
9
9
|
end
|
10
|
-
def parser
|
11
|
-
@parser ||= default_parser
|
12
|
-
end
|
13
10
|
|
14
11
|
def load_defaults?
|
15
|
-
@load_defaults
|
16
|
-
end
|
17
|
-
|
18
|
-
def parser=(name)
|
19
|
-
Clitopic::Command::Base.extend name
|
20
|
-
@parser = name
|
12
|
+
@load_defaults
|
21
13
|
end
|
22
14
|
|
23
|
-
def default_parser
|
24
|
-
@default_parsre ||= Clitopic::Parser::OptParser
|
25
|
-
end
|
26
15
|
end
|
27
16
|
end
|
28
17
|
|
@@ -30,8 +19,8 @@ end
|
|
30
19
|
# Defaults
|
31
20
|
Clitopic.name = "clitopic"
|
32
21
|
Clitopic.debug = false
|
33
|
-
Clitopic.version = Clitopic::VERSION
|
34
22
|
Clitopic.load_defaults = true
|
23
|
+
Clitopic.version = Clitopic::VERSION
|
35
24
|
Clitopic.default_files = [File.join(Dir.getwd, ".clitopic.yml"), File.join(Dir.home, ".clitopic.yml")]
|
36
25
|
|
37
26
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Clitopic do
|
5
|
+
context 'global command load_defaults' do
|
6
|
+
it 'option --defaults-file should be added to common options' do
|
7
|
+
expect(Clitopic::Commands.global_options).to include (a_hash_including({:name => :load_defaults, :args =>[ "--defaults-file FILE", "Load default variables"]}))
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should not fail to load a default file' do
|
11
|
+
temp = Tempfile.new('load_file')
|
12
|
+
Clitopic::Command::DefaultsFile.arguments = [temp.path]
|
13
|
+
Clitopic::Command::DefaultsFile.options = {:force => false}
|
14
|
+
opts = Clitopic::Command::DefaultsFile.call
|
15
|
+
cmd = Clitopic::Commands.global_options.select{|a| a[:name] == :load_defaults}.first
|
16
|
+
Clitopic::Commands.current_cmd = Clitopic::Command::Help
|
17
|
+
cmd[:proc].call(temp.path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context 'load_defaults?' do
|
21
|
+
it 'should be true by default' do
|
22
|
+
expect(Clitopic.load_defaults?).to be true
|
23
|
+
end
|
24
|
+
it 'should be false if set to' do
|
25
|
+
Clitopic.load_defaults = false
|
26
|
+
expect(Clitopic.load_defaults?).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Clitopic::Command::Suggestions do
|
4
|
+
context 'Prefix' do
|
5
|
+
it 'Call uncompleted command should display list of commands' do
|
6
|
+
Clitopic::Command::Suggestions.arguments = ["clito:"]
|
7
|
+
response = ["clito:defaults_file", "clito:suggestions", "clito:version"].join("\n") + "\n"
|
8
|
+
|
9
|
+
|
10
|
+
expect{Clitopic::Command::Suggestions.call}.to output(response).to_stdout
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context 'Mistake' do
|
14
|
+
it 'Command `hep` should propose `help`' do
|
15
|
+
Clitopic::Command::Suggestions.arguments = ["hep"]
|
16
|
+
expect{Clitopic::Command::Suggestions.call}.to output("help\n").to_stdout
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Clitopic::Command::ClitoVersion do
|
4
|
+
context 'call' do
|
5
|
+
it 'should returns current cli-topic version' do
|
6
|
+
expect{Clitopic::Command::ClitoVersion.call}.to output("cli-topic version: #{Clitopic::VERSION}\n").to_stdout
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-topic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Legrand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -51,6 +51,11 @@ files:
|
|
51
51
|
- lib/clitopic/topics.rb
|
52
52
|
- lib/clitopic/utils.rb
|
53
53
|
- lib/clitopic/version.rb
|
54
|
+
- spec/clitopic_spec.rb
|
55
|
+
- spec/command/clito_defaults_file_spec.rb
|
56
|
+
- spec/command/clito_suggestions_spec.rb
|
57
|
+
- spec/command/clito_version_spec.rb
|
58
|
+
- spec/command/version_spec.rb
|
54
59
|
- spec/command_base_spec.rb
|
55
60
|
- spec/commands_spec.rb
|
56
61
|
- spec/spec_helper.rb
|
@@ -91,6 +96,11 @@ summary: '["Small framework to build CLI.", "Small framework to build CLI organi
|
|
91
96
|
"lib/clitopic/topic/base.rb", "lib/clitopic/topics.rb", "lib/clitopic/utils.rb",
|
92
97
|
"lib/clitopic/version.rb"]]'
|
93
98
|
test_files:
|
99
|
+
- spec/clitopic_spec.rb
|
100
|
+
- spec/command/clito_defaults_file_spec.rb
|
101
|
+
- spec/command/clito_suggestions_spec.rb
|
102
|
+
- spec/command/clito_version_spec.rb
|
103
|
+
- spec/command/version_spec.rb
|
94
104
|
- spec/command_base_spec.rb
|
95
105
|
- spec/commands_spec.rb
|
96
106
|
- spec/spec_helper.rb
|