Class: Pups::Cli
- Inherits:
-
Object
- Object
- Pups::Cli
- Defined in:
- lib/pups/cli.rb
Class Method Summary collapse
Class Method Details
.opts ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pups/cli.rb', line 7 def self.opts OptionParser.new do |opts| opts. = "Usage: pups [FILE|--stdin]" opts.on("--stdin", "Read input from stdin.") opts.on("--quiet", "Don't print any logs.") opts.on( "--ignore <element(s)>", Array, "Ignore these template configuration elements, multiple elements can be provided (comma-delimited)." ) opts.on( "--gen-docker-run-args", "Output arguments from the pups configuration for input into a docker run command. All other pups config is ignored." ) opts.on("--tags <tag(s)>", Array, "Only run tagged commands.") opts.on( "--skip-tags <tag(s)>", Array, "Run all but listed tagged commands." ) opts.on( "--params <param(s)>", Array, "Replace params in the config with params listed." ) opts.on("-h", "--help") do puts opts exit end end end |
.parse_args(args) ⇒ Object
39 40 41 42 43 |
# File 'lib/pups/cli.rb', line 39 def self.parse_args(args) = {} opts.parse!(args, into: ) end |
.run(args) ⇒ Object
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 91 92 93 94 95 96 97 98 99 |
# File 'lib/pups/cli.rb', line 45 def self.run(args) = parse_args(args) input_file = [:stdin] ? "stdin" : args.last unless input_file puts opts.parse!(%w[--help]) exit end Pups.silence if [:quiet] Pups.log.info("Reading from #{input_file}") if [:stdin] conf = $stdin.readlines.join split = conf.split("_FILE_SEPERATOR_") conf = nil split.each do |data| current = YAML.safe_load(data.strip) conf = if conf Pups::MergeCommand.deep_merge(conf, current, :merge_arrays) else current end end config = Pups::Config.new( conf, [:ignore], tags: [:tags], skip_tags: [:"skip-tags"], extra_params: [:params] ) else config = Pups::Config.load_file( input_file, [:ignore], tags: [:tags], skip_tags: [:"skip-tags"], extra_params: [:params] ) end if [:"gen-docker-run-args"] print config.generate_docker_run_arguments return end config.run ensure Pups::ExecCommand.terminate_async end |