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