Class: SnippetCli::Commands::Setup

Inherits:
SnippetCli::Command show all
Defined in:
lib/snippet_cli/commands/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SnippetCli::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initializeSetup

Returns a new instance of Setup.



16
17
18
19
20
21
22
# 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

Instance Attribute Details

#config_pathObject

Returns the value of attribute config_path.



14
15
16
# File 'lib/snippet_cli/commands/setup.rb', line 14

def config_path
  @config_path
end

#config_presentObject

Returns the value of attribute config_present.



14
15
16
# File 'lib/snippet_cli/commands/setup.rb', line 14

def config_present
  @config_present
end

#os_choiceObject

Returns the value of attribute os_choice.



14
15
16
# File 'lib/snippet_cli/commands/setup.rb', line 14

def os_choice
  @os_choice
end

#user_nameObject

Returns the value of attribute user_name.



14
15
16
# File 'lib/snippet_cli/commands/setup.rb', line 14

def user_name
  @user_name
end

#user_storageObject

Returns the value of attribute user_storage.



14
15
16
# File 'lib/snippet_cli/commands/setup.rb', line 14

def user_storage
  @user_storage
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# 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_configObject



85
86
87
88
89
90
91
92
# 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_nameObject



39
40
41
42
43
44
45
46
47
# 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_osObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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_storageObject

REFACTOR TO PROVIDE PATH



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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

#show_bannerObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/snippet_cli/commands/setup.rb', line 24

def show_banner()
  box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do 
  "
  #####   #     # ### ######  ######  ####### ####### 
  #     # ##    #  #  #     # #     # #          #    
  #       # #   #  #  #     # #     # #          #    
   #####  #  #  #  #  ######  ######  #####      #    
        # #   # #  #  #       #       #          #    
  #     # #    ##  #  #       #       #          #    
   #####  #     # ### #       #       #######    #    CLI                                                                
  "
  end
  puts box
end