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
- ARRAY_FLAGS =
[:set]
- 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. Returns an array of the options set" }
- 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", :non_interactive => "Avoid all prompts and use defaults for any option that requires user input", :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.
-
#non_interactive ⇒ Object
readonly
Returns the value of attribute non_interactive.
-
#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
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 86 87 88 89 |
# File 'lib/schema-evolution-manager/args.rb', line 38 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) @non_interactive = found_arguments.delete(:non_interactive) @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.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def artifact_name @artifact_name end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def dir @dir end |
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def dry_run @dry_run end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def name @name end |
#non_interactive ⇒ Object (readonly)
Returns the value of attribute non_interactive.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def non_interactive @non_interactive end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def port @port end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def prefix @prefix end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def set @set end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def tag @tag end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
33 34 35 |
# File 'lib/schema-evolution-manager/args.rb', line 33 def user @user end |