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" } contents = "" contents << "email=#{email}\n" contents << "cloud-proxy-path=#{File.expand_path(cloud_proxy_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