Sha256: f4a69478b38ddc7277f1f1cda88e751e653ee0c5b4a2701f99398589ca13655f

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'sct/command_interface'
require 'highline'

module Sct

  class InitCommand

    IS_PUBLIC_COMMAND = true
    SYNTAX = 'sct init'
    SUMMARY = 'Initialize a base configuration file for sct'
    EXAMPLE = 'sct init'
    EXAMPLE_DESCRIPTION = 'sct init will create a configuration file'
    DESCRIPTION = "sct init will create a configuration file"

    OPTIONS = []

    def initialize
    end

    def execute(args, options)

      Sct::Config.dir

      cli = HighLine.new

      email = cli.ask("What is your email address?") { |q|
          q.validate = URI::MailTo::EMAIL_REGEXP
      }

      cloud_proxy_path = cli.ask("What is the path of your cloud proxy json credentials?") { |q|
          q.default = "~/.config/gcloud/application_default_credentials.json"
      }

      host_path = cli.choose do |menu|
          menu.prompt = "What is the path of your hostfile?"
          menu.choice(:unix) { "/etc/hosts" }
          menu.choices(:windows) { "/mnt/c/Windows/System32/drivers/etc/hosts" }
          menu.default = :unix
      end

      contents = ""
      contents << "email=#{email}\n"
      contents << "cloud-proxy-path=#{File.expand_path(cloud_proxy_path)}\n"
      contents << "host-path=#{File.expand_path(host_path)}\n"

      if !File.directory?(Sct::Config.dir)
          FileUtils.mkdir_p(Sct::Config.dir)
      end

      File.write(Sct::Config.path, contents)

      puts "Generated config file at #{Sct::Config.path}"
    end

    implements CommandInterface

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sct-0.1.6 lib/sct/commands/init.rb
sct-0.1.5 lib/sct/commands/init.rb
sct-0.1.4 lib/sct/commands/init.rb