class SnippetCli::Commands::Setup
Attributes
config_path[RW]
config_present[RW]
os_choice[RW]
user_name[RW]
user_storage[RW]
Public Class Methods
new()
click to toggle source
# File lib/snippet_cli/commands/setup.rb, line 16 def initialize() @user_name = user_name @config_path = config_path @user_storage = user_storage @os_choice = os_choice @config_present = config_present end
Public Instance Methods
execute(input: $stdin, output: $stdout)
click to toggle source
# File lib/snippet_cli/commands/setup.rb, line 94 def execute(input: $stdin, output: $stdout) show_banner() self.get_name() self.get_os() output.puts @leading output.puts "Thanks, that's all we need to know about your configuration." output.puts @leading output.puts @leading output.puts "You can now type snippet_cli new to get started." output.puts @leading self.generate_config() end
generate_config()
click to toggle source
# File lib/snippet_cli/commands/setup.rb, line 85 def generate_config() if File.exist?("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt") && File.read("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt").include?("CONFIG_PRESENT = TRUE") else File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "NAME = #{self.user_name}\n"} File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "#{self.config_path}\n"} File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "CONFIG_PRESENT = TRUE\n"} end end
get_name()
click to toggle source
# File lib/snippet_cli/commands/setup.rb, line 39 def get_name() puts @leading prompt = TTY::Prompt.new name = prompt.ask("⟶ To begin setup, may I have your name?", default: ENV["USER"], active_color: :bright_blue) do |q| q.required true end puts @leading self.user_name = name end
get_os()
click to toggle source
# File lib/snippet_cli/commands/setup.rb, line 49 def get_os() puts @leading puts "Checking what os you're using..." os_choice = platform.os() if (platform.windows? == true) config_path = "#{ENV["HOMEPATH"]}\\AppData\\Roaming\\espanso\\default.yml" elsif (platform.mac? == true) config_path = "#{ENV["HOME"]}/Library/Preferences/espanso/default.yml" else (platform.linux? == true) config_path = "#{ENV["HOME"]}/.config/espanso/default.yml" end puts @leading self.config_path=config_path self.os_choice = os_choice puts "We'll set the config path to:" puts @leading prompt.ok("#{config_path}") end
get_storage()
click to toggle source
REFACTOR TO PROVIDE PATH
# File lib/snippet_cli/commands/setup.rb, line 70 def get_storage() puts @leading prompt = TTY::Prompt.new return snippet_storage = prompt.select("Do your store your snippets in Dropbox or a different directory?", default: 1, active_color: :bright_blue) do |menu| menu.enum "." menu.choice "No I use the default folder.", 1 menu.choice "I use Dropbox.", 2 menu.choice "I use Google Drive", 3 menu.choice "I use Another Directory.", 4 end puts @leading self.user_storage = snippet_storage end