Sha256: 49196ba21be41bf2f8ac2c57172f69618ccbb8e8e51f200b3d37dd96349ae7e2

Contents?: true

Size: 1.65 KB

Versions: 25

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# Example of a simple command line tool to manage configuration files
# ad_config -p settings,channels
# ad_config -p
# ad_config -l
# ad_config -c
# ad_config -e

$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))

require 'pry'
require 'appydave/tools'

options = { keys: [] }

OptionParser.new do |opts|
  opts.banner = 'Usage: config_tool.rb [options]'

  opts.on('-e', '--edit', 'Edit configuration in Visual Studio Code') do
    options[:command] = :edit
  end

  opts.on('-l', '--list', 'List all configurations') do
    options[:command] = :list
  end

  opts.on('-c', '--create', 'Create missing configurations') do
    options[:command] = :create
  end

  opts.on('-p', '--print [KEYS]', Array, 'Print configuration details for specified keys') do |keys|
    options[:command] = :print
    options[:keys] = keys
  end

  opts.on_tail('-h', '--help', 'Show this message') do
    puts opts
    exit
  end
end.parse!

case options[:command]
when :edit
  Appydave::Tools::Configuration::Config.edit
when :list
  Appydave::Tools::Configuration::Config.configure
  configurations = Appydave::Tools::Configuration::Config.configurations.map do |name, config|
    { name: name, path: config.config_path, exists: File.exist?(config.config_path) }
  end
  tp configurations, :name, :exists, { path: { width: 150 } }
when :create
  Appydave::Tools::Configuration::Config.configure
  Appydave::Tools::Configuration::Config.save
when :print
  Appydave::Tools::Configuration::Config.configure
  Appydave::Tools::Configuration::Config.print(*options[:keys])
else
  puts 'No valid command provided. Use --help for usage information.'
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
appydave-tools-0.11.11 bin/configuration.rb
appydave-tools-0.11.10 bin/configuration.rb
appydave-tools-0.11.9 bin/configuration.rb
appydave-tools-0.11.8 bin/configuration.rb
appydave-tools-0.11.7 bin/configuration.rb
appydave-tools-0.11.6 bin/configuration.rb
appydave-tools-0.11.5 bin/configuration.rb
appydave-tools-0.11.4 bin/configuration.rb
appydave-tools-0.11.3 bin/configuration.rb
appydave-tools-0.11.2 bin/configuration.rb
appydave-tools-0.11.1 bin/configuration.rb
appydave-tools-0.11.0 bin/configuration.rb
appydave-tools-0.10.4 bin/configuration.rb
appydave-tools-0.10.3 bin/configuration.rb
appydave-tools-0.10.2 bin/configuration.rb
appydave-tools-0.10.1 bin/configuration.rb
appydave-tools-0.10.0 bin/configuration.rb
appydave-tools-0.9.5 bin/configuration.rb
appydave-tools-0.9.4 bin/configuration.rb
appydave-tools-0.9.3 bin/configuration.rb