Class: KubeDeployTools::Deploy::Optparser::Options
- Defined in:
- lib/kube_deploy_tools/deploy/options.rb
Instance Attribute Summary collapse
-
#artifact ⇒ Object
Returns the value of attribute artifact.
-
#build_number ⇒ Object
Returns the value of attribute build_number.
-
#context ⇒ Object
Returns the value of attribute context.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#flavor ⇒ Object
Returns the value of attribute flavor.
-
#from_files ⇒ Object
Returns the value of attribute from_files.
-
#glob_files ⇒ Object
Returns the value of attribute glob_files.
-
#kubeconfig ⇒ Object
Returns the value of attribute kubeconfig.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#pre_apply_hook ⇒ Object
Returns the value of attribute pre_apply_hook.
-
#project ⇒ Object
Returns the value of attribute project.
-
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
Instance Method Summary collapse
- #define_options(parser) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #require_options ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
21 22 23 24 25 26 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 21 def initialize self.project = File.basename(`git config remote.origin.url`.chomp, '.git') self.flavor = 'default' self.dry_run = true self.glob_files = [] end |
Instance Attribute Details
#artifact ⇒ Object
Returns the value of attribute artifact.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def artifact @artifact end |
#build_number ⇒ Object
Returns the value of attribute build_number.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def build_number @build_number end |
#context ⇒ Object
Returns the value of attribute context.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def context @context end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def dry_run @dry_run end |
#flavor ⇒ Object
Returns the value of attribute flavor.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def flavor @flavor end |
#from_files ⇒ Object
Returns the value of attribute from_files.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def from_files @from_files end |
#glob_files ⇒ Object
Returns the value of attribute glob_files.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def glob_files @glob_files end |
#kubeconfig ⇒ Object
Returns the value of attribute kubeconfig.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def kubeconfig @kubeconfig end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def max_retries @max_retries end |
#pre_apply_hook ⇒ Object
Returns the value of attribute pre_apply_hook.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def pre_apply_hook @pre_apply_hook end |
#project ⇒ Object
Returns the value of attribute project.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def project @project end |
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
8 9 10 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 8 def retry_delay @retry_delay end |
Instance Method Details
#define_options(parser) ⇒ Object
28 29 30 31 32 33 34 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 86 87 88 89 90 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 28 def (parser) parser.on('-fPATH', '--from-files FILEPATH', 'Filename, directory, or artifact URL that contains the Kubernetes manifests to apply') do |p| self.from_files = p end parser.on('--kubeconfig FILEPATH', 'Path to the kubconfig file to use for kubectl requests') do |p| self.kubeconfig = p end parser.on('--context CONTEXT', 'The kubeconfig context to use') do |p| self.context = p end parser.on('--project PROJECT', "The project to deploy. Default is '#{project}'.") do |p| self.project = p end parser.on('--flavor FLAVOR', "The flavor to deploy. Default is '#{flavor}'") do |p| self.flavor = p end parser.on('--artifact ARTIFACT', 'The artifact name to deploy') do |p| self.artifact = p end parser.on('--build BUILD', 'The Jenkins build number to deploy') do |p| self.build_number = p end parser.on('--dry-run DRY_RUN', TrueClass, "If true, will only dry-run apply Kubernetes manifests without sending them to the apiserver. Default is dry-run mode: #{dry_run}.") do |p| self.dry_run = p end parser.on('--include INCLUDE', "Include glob pattern. Example: --include=**/* will include every file. Default is ''.") do |p| self.glob_files.push(["include_files", p]) end parser.on('--exclude EXCLUDE', "Exclude glob pattern. Example: --exclude=**/gazette/* will exclude every file in gazette folder. Default is ''.") do |p| self.glob_files.push(["exclude_files", p]) end parser.on('--include-dir INCLUDE', "Recursively include all files in a directory and its subdirectories. Example: --include-dir=gazette/ (equivalent of --include=**/gazette/**/*)") do |p| self.glob_files.push(["include_dir", p]) end parser.on('--exclude-dir EXCLUDE', "Recursively exclude all files in a directory and its subdirectories. Example: --exclude-dir=gazette/ (equivalent of --exclude=**/gazette/**/*)") do |p| self.glob_files.push(["exclude_dir", p]) end parser.on("--pre-apply-hook CMD", "Shell command to run with the output directory before applying files") do |p| self.pre_apply_hook = p end parser.on('--retry NUM', 'Maximum number of times to retry') do |p| self.max_retries = p end parser.on('--retry-delay NUM', 'Delay in seconds between retries') do |p| self.retry_delay = p end parser.on('-') end |
#require_options ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kube_deploy_tools/deploy/options.rb', line 92 def raise ArgumentError, 'Expect --context to be provided' if context.blank? files_mode = from_files.present? && (artifact.blank? && build_number.blank?) deploy_artifact_mode = from_files.blank? && (artifact.present? && flavor.present? && build_number.present?) if !files_mode && !deploy_artifact_mode raise ArgumentError, 'Expect either --from-files or all of [--artifact, --flavor, --build] to be provided' end end |