Class: SchemaEvolutionManager::Args
- Inherits:
-
Object
- Object
- SchemaEvolutionManager::Args
- Defined in:
- lib/schema-evolution-manager/args.rb
Overview
Container for common args, mainly to have stricter validation on inputs. Tried to use GetoptLong but could not write solid unit tests around it… so we have our own internal simple implementation.
Constant Summary collapse
- FLAGS_WITH_ARGUMENTS =
{ :artifact_name => "Specifies the name of the artifact. Tag will be appended to this name", :user => "Connect to the database as this username instead of the default", :host => "Specifies the host name of the machine on which the server is running", :port => "Specifies the port on which the server is running", :name => "Specifies the name of the database to which to connect", :url => "The connection string for the psql database", :dir => "Path to a directory", :tag => "A git tag (e.g. 0.0.1)", :prefix => "Configure installer to use this prefix", :set => "Passthrough for postgresql --set argument" }
- FLAGS_NO_ARGUMENTS =
{ :password => "Prompt user to enter password for the database user. Password is stored for the duration of the process", :dry_run => "Include flag to echo commands that will run without actually executing them", :help => "Display help", :verbose => "Enable verbose logging of all system calls", }
Instance Attribute Summary collapse
-
#artifact_name ⇒ Object
readonly
Returns the value of attribute artifact_name.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.from_stdin(opts) ⇒ Object
Hack to minimize bleeding from STDIN.
Instance Method Summary collapse
-
#initialize(args, opts = {}) ⇒ Args
constructor
args: Actual string arguments :required => list of parameters that are required :optional => list of parameters that are optional.
Constructor Details
#initialize(args, opts = {}) ⇒ Args
args: Actual string arguments :required => list of parameters that are required :optional => list of parameters that are optional
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/schema-evolution-manager/args.rb', line 35 def initialize(args, opts={}) Preconditions.assert_class_or_nil(args, String) required = (opts.delete(:required) || []).map { |flag| format_flag(flag) } optional = (opts.delete(:optional) || []).map { |flag| format_flag(flag) } Preconditions.assert_class(required, Array) Preconditions.assert_class(optional, Array) Preconditions.assert_empty_opts(opts) Preconditions.check_state(optional.size + required.size > 0, "Must have at least 1 optional or required parameter") if !optional.include?(:help) optional << :help end if !optional.include?(:verbose) optional << :verbose end found_arguments = parse_string_arguments(args) missing = required.select { |field| blank?(found_arguments[field]) } @artifact_name = found_arguments.delete(:artifact_name) @host = found_arguments.delete(:host) @port = found_arguments.delete(:port) @name = found_arguments.delete(:name) @prefix = found_arguments.delete(:prefix) @url = found_arguments.delete(:url) @user = found_arguments.delete(:user) @dir = found_arguments.delete(:dir) @tag = found_arguments.delete(:tag) @set = found_arguments.delete(:set) @dry_run = found_arguments.delete(:dry_run) @password = found_arguments.delete(:password) @help = found_arguments.delete(:help) @verbose = found_arguments.delete(:verbose) Preconditions.check_state(found_arguments.empty?, "Did not handle all flags: %s" % found_arguments.keys.join(" ")) if @help RdocUsage.printAndExit(0) end if @verbose Library.set_verbose(true) end if !missing.empty? missing_fields_error(required, optional, missing) end end |
Instance Attribute Details
#artifact_name ⇒ Object (readonly)
Returns the value of attribute artifact_name.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def artifact_name @artifact_name end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def dir @dir end |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def dry_run @dry_run end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def name @name end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def port @port end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def prefix @prefix end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def set @set end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def tag @tag end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
30 31 32 |
# File 'lib/schema-evolution-manager/args.rb', line 30 def user @user end |
Class Method Details
.from_stdin(opts) ⇒ Object
Hack to minimize bleeding from STDIN. Returns an instance of Args class
88 89 90 91 |
# File 'lib/schema-evolution-manager/args.rb', line 88 def Args.from_stdin(opts) values = ARGV.join(" ") Args.new(values, opts) end |