Module: GClouder::Config::CLIArgs
- Included in:
- GClouder, Files::Project, GCloud, GSUtil, Project::ID, Resource, Resources::Compute::BGPVPNs, Resources::Compute::BGPVPNs::BGPVPN, Resources::Compute::Disks, Resources::Compute::FirewallRules, Resources::Compute::Instances, Resources::Compute::Networks, Resources::Compute::Networks::Local, Resources::Compute::Networks::Subnets, Resources::Compute::ProjectInfo::SSHKeys, Resources::Compute::Routers, Resources::Compute::VPNs, Resources::Compute::VPNs::VPN, Resources::Container::Clusters::Cluster, Resources::Container::NodePools::NodePool, Resources::DNS, Resources::DNS::Records, Resources::Functions::Function, Resources::Functions::Function::Local, Resources::Global, Resources::Logging::Sinks, Resources::Logging::Sinks::Local, Resources::Project::IAMPolicyBinding, Resources::Project::Local, Resources::PubSub::Subscriptions, Resources::PubSub::Subscriptions::Local, Resources::PubSub::Topics, Resources::PubSub::Topics::Local, Resources::Region, Resources::RuntimeConfig::Configs, Resources::RuntimeConfig::Configs::Local, Resources::RuntimeConfig::Variables, Resources::RuntimeConfig::Variables::Local, Resources::Storage::Buckets::Bucket, Resources::Storage::Notifications::Notification, Resources::Validate::Global, Resources::Validate::Region, Resources::Validate::Remote
- Defined in:
- lib/gclouder/config/cli_args.rb
Class Method Summary collapse
- .check ⇒ Object
- .cli_args ⇒ Object
- .included(klass) ⇒ Object
- .load ⇒ Object
- .valid_resources ⇒ Object
Instance Method Summary collapse
Class Method Details
.check ⇒ Object
73 74 75 76 |
# File 'lib/gclouder/config/cli_args.rb', line 73 def self.check raise ArgumentError, "config file not specified" unless cli_args[:config_given] raise ArgumentError, "config file not readable: #{cli_args[:config]}" unless File.readable?(cli_args[:config]) end |
.cli_args ⇒ Object
6 7 8 |
# File 'lib/gclouder/config/cli_args.rb', line 6 def self.cli_args @cli_args ||= { debug: false } end |
.included(klass) ⇒ Object
14 15 16 |
# File 'lib/gclouder/config/cli_args.rb', line 14 def self.included(klass) klass.extend CLIArgs end |
.load ⇒ Object
22 23 24 25 26 27 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 |
# File 'lib/gclouder/config/cli_args.rb', line 22 def self.load option_parser = Trollop::Parser.new do GClouder::Header.display + "\n \n " # required opt :config, "path to config file\n ", type: :string, required: true # level of operation opt :dry_run, "passive mode" opt :purge, "remove unmanaged resources (destructive!)\n " # authentication / for automation opt :activate_service_accounts, "activate service account(s) (for use when running using service accounts, i.e: with CI)" opt :keys_dir, "path to directory with service account key files (for use with --activate-service-accounts)\n ", type: :string opt :ignore_default_service_account, "don't attempt to switch back to a default service account for the environment" # which resources / actions # FIXME: integrate checks for required permissions into Project module opt :bootstrap, "create project (requires being run as non-service account)" # this should be type: proc and validate that the params match one of: validate, ensure, clean opt :stages, "which stages to run (validate,ensure,clean) [csv]", type: :string opt :resources, "which resources to update [csv]", type: :string opt :skip_cross_project_resources, "skip resources which don't reside in main project\n " # output opt :debug, "print commands to be executed, and stack traces" opt :trace, "print stack traces" opt :no_color, "disable color\n \n " end @cli_args = Trollop.with_standard_exception_handling(option_parser) do raise Trollop::HelpNeeded if ARGV.empty? option_parser.parse ARGV end String.disable_colorization = @cli_args[:no_color] if @cli_args[:resources] @cli_args[:resources].split(',').each do |resource| unless valid_resources.include?(resource) puts "valid resources: #{valid_resources.join(', ')}" puts "invalid resource for --resources flag: #{resource}" exit 1 end end end check end |
.valid_resources ⇒ Object
18 19 20 |
# File 'lib/gclouder/config/cli_args.rb', line 18 def self.valid_resources GClouder.resources.map { |resource| resource[:name] } end |