configliere 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/configliere.gemspec +3 -2
- data/lib/configliere.rb +1 -1
- data/lib/configliere/commandline.rb +10 -8
- data/lib/configliere/define.rb +1 -1
- data/lib/configliere/git_style_binaries.rb +74 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/configliere.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configliere}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mrflip"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-02}
|
13
13
|
s.default_executable = %q{configliere}
|
14
14
|
s.description = %q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
15
15
|
|
@@ -50,6 +50,7 @@ Configliere manage settings from many sources: static constants, simple config f
|
|
50
50
|
"lib/configliere/define.rb",
|
51
51
|
"lib/configliere/encrypted.rb",
|
52
52
|
"lib/configliere/env_var.rb",
|
53
|
+
"lib/configliere/git_style_binaries.rb",
|
53
54
|
"lib/configliere/param.rb",
|
54
55
|
"spec/configliere/commandline_spec.rb",
|
55
56
|
"spec/configliere/config_block_spec.rb",
|
data/lib/configliere.rb
CHANGED
@@ -10,7 +10,7 @@ module Configliere
|
|
10
10
|
Configliere::Param.new *args, &block
|
11
11
|
end
|
12
12
|
|
13
|
-
ALL_MIXINS = [:define, :config_file, :commandline, :encrypted, :env_var, :config_block]
|
13
|
+
ALL_MIXINS = [:define, :config_file, :commandline, :encrypted, :env_var, :config_block, :git_style_binaries]
|
14
14
|
def self.use *mixins
|
15
15
|
mixins = ALL_MIXINS if mixins.include?(:all) || mixins.empty?
|
16
16
|
mixins.each do |mixin|
|
@@ -53,10 +53,6 @@ module Configliere
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
# If your script uses the 'script_name verb [...params...]'
|
57
|
-
# pattern, list the commands here:
|
58
|
-
COMMANDS= {}
|
59
|
-
|
60
56
|
# Configliere internal params
|
61
57
|
def define_special_params
|
62
58
|
Settings.define :encrypt_pass, :description => "Passphrase to extract encrypted config params.", :internal => true
|
@@ -72,8 +68,7 @@ module Configliere
|
|
72
68
|
# @param str [String] the string to dump out before exiting
|
73
69
|
# @param exit_code [Integer] UNIX exit code to set, default -1
|
74
70
|
def die str, exit_code=-1
|
75
|
-
|
76
|
-
warn "\n****\n#{str}\n****"
|
71
|
+
dump_help "****\n#{str}\n****"
|
77
72
|
exit exit_code
|
78
73
|
end
|
79
74
|
|
@@ -84,22 +79,29 @@ module Configliere
|
|
84
79
|
self[attr] = ask("#{attr}"+(hint ? " for #{hint}?" : '?'))
|
85
80
|
end
|
86
81
|
|
82
|
+
# The contents of the help message.
|
83
|
+
# Lists the usage as well as any defined parameters and environment variables
|
87
84
|
def help
|
88
85
|
help_str = [ usage ]
|
89
86
|
help_str += [ "\nParams:", descriptions.sort_by{|p,d| p.to_s }.map{|param, desc| " --%-25s %s"%[param.to_s+':', desc]}.join("\n"), ] if respond_to?(:descriptions)
|
90
|
-
# help_str += ["\nCommands", commands.map{|cmd, desc| " %-20s %s"%[cmd.to_s+':', desc]}.join("\n")] if respond_to?(:commands)
|
91
87
|
help_str += [ "\nEnvironment Variables can be used to set:", params_from_env_vars.map{|param, env| " %-27s %s"%[env.to_s+':', param]}.join("\n"), ] if respond_to?(:params_from_env_vars)
|
92
88
|
help_str.join("\n")
|
93
89
|
end
|
94
90
|
|
91
|
+
# Output the help message to $stderr, along with an optional extra message appended.
|
95
92
|
def dump_help extra_msg=nil
|
96
93
|
$stderr.puts help
|
97
94
|
$stderr.puts "\n\n"+extra_msg unless extra_msg.blank?
|
95
|
+
$stderr.puts ''
|
96
|
+
end
|
97
|
+
|
98
|
+
def raw_script_name
|
99
|
+
File.basename($0)
|
98
100
|
end
|
99
101
|
|
100
102
|
# Usage line
|
101
103
|
def usage
|
102
|
-
%Q{usage: #{
|
104
|
+
%Q{usage: #{raw_script_name} [...--param=val...]}
|
103
105
|
end
|
104
106
|
|
105
107
|
protected
|
data/lib/configliere/define.rb
CHANGED
@@ -52,7 +52,7 @@ module Configliere
|
|
52
52
|
|
53
53
|
# All described params with their descriptions
|
54
54
|
def descriptions
|
55
|
-
definitions_for(:description).reject{|param, desc| param_definitions[param][:hide_help] }
|
55
|
+
definitions_for(:description) # .reject{|param, desc| param_definitions[param][:hide_help] }
|
56
56
|
end
|
57
57
|
|
58
58
|
# List of params that have descriptions
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'configliere/commandline'
|
2
|
+
module Configliere
|
3
|
+
|
4
|
+
# If your script uses the 'script_name verb [...params...]'
|
5
|
+
# pattern, list the commands here:
|
6
|
+
Configliere::COMMANDS = []
|
7
|
+
|
8
|
+
# Add a command, along with a description of its predicates and the command itself.
|
9
|
+
def self.define_command cmd, preds_desc=nil, desc=nil
|
10
|
+
Configliere::COMMANDS << [cmd, preds_desc, (desc || "#{cmd} command")]
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Command line tool to manage param info
|
15
|
+
#
|
16
|
+
# To include, specify
|
17
|
+
#
|
18
|
+
# Configliere.use :git_style_binaries
|
19
|
+
#
|
20
|
+
module GitStyleBinaries
|
21
|
+
attr_accessor :command
|
22
|
+
|
23
|
+
#
|
24
|
+
# Parse the command-line args into the params hash.
|
25
|
+
#
|
26
|
+
# '--happy_flag' produces :happy_flag => true in the params hash
|
27
|
+
# '--foo=foo_val' produces :foo => 'foo_val' in the params hash.
|
28
|
+
# '--' Stop parsing; all remaining args are piled into :rest
|
29
|
+
#
|
30
|
+
# self.rest contains all arguments that don't start with a '--'
|
31
|
+
# and all args following the '--' sentinel if any.
|
32
|
+
#
|
33
|
+
def process_argv!
|
34
|
+
super
|
35
|
+
if raw_script_name =~ /(\w+)-([\w\-]+)/
|
36
|
+
self.command = $2
|
37
|
+
else
|
38
|
+
self.command = rest.shift
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# The script name without command appendix if any: For $0 equal to any of
|
43
|
+
# 'git', 'git-reset', or 'git-cherry-pick', base_script_name is 'git'
|
44
|
+
#
|
45
|
+
def base_script_name
|
46
|
+
raw_script_name.gsub(/-.*/, '')
|
47
|
+
end
|
48
|
+
|
49
|
+
# The contents of the help message. Dumps the standard commandline help
|
50
|
+
# message, and then lists the commands with their description.
|
51
|
+
def help
|
52
|
+
help_str = super()
|
53
|
+
help_str << "\n\nCommands:\n"
|
54
|
+
COMMANDS.map do |cmd, cmd_params, desc|
|
55
|
+
cmd_template = " %-49s" % [base_script_name, cmd, cmd_params].join(" ")
|
56
|
+
cmd_template += " :: " + desc if desc
|
57
|
+
help_str << cmd_template+"\n"
|
58
|
+
end
|
59
|
+
help_str
|
60
|
+
end
|
61
|
+
|
62
|
+
# Usage line
|
63
|
+
def usage
|
64
|
+
%Q{usage: #{base_script_name} command [...--param=val...]}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Param.class_eval do
|
69
|
+
# include command syntax methods in chain. Since commandline is required
|
70
|
+
# first at the top of this file, GitStyleBinaries methods sit below
|
71
|
+
# Commandline methods in the superclass chain.
|
72
|
+
include GitStyleBinaries
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- mrflip
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-02 00:00:00 -05:00
|
18
18
|
default_executable: configliere
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/configliere/define.rb
|
81
81
|
- lib/configliere/encrypted.rb
|
82
82
|
- lib/configliere/env_var.rb
|
83
|
+
- lib/configliere/git_style_binaries.rb
|
83
84
|
- lib/configliere/param.rb
|
84
85
|
- spec/configliere/commandline_spec.rb
|
85
86
|
- spec/configliere/config_block_spec.rb
|