Class: Lac::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/lac/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CLI

Returns a new instance of CLI.



11
12
13
# File 'lib/lac/cli.rb', line 11

def initialize(arguments)
  @action = arguments[0]
end

Instance Method Details

#create_projectObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lac/cli.rb', line 31

def create_project
    puts "Hello! Welcome to Lac".bold
    puts "This is a work in progress. Check out the Git repo if you would like to contribute.".bold
    puts "Type 'exit' to quit"
    project_name = nil
    
    while project_name == nil
      input = prompt_input("Choose a name for your project: ")
      if File.directory?("./#{input}")
        puts "A folder with that name already exists, choose another name:"
      else
        project_name = input
      end
    end
     
    `mkdir #{project_name}`
    if File.directory?("./#{project_name}")
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/"
      
      `mkdir #{project_name}/config`
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/config"

      `mkdir #{project_name}/cache`
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/cache"

      `mkdir #{project_name}/models`
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/models"

      `mkdir #{project_name}/scrapers`
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/scrapers"

      `mkdir #{project_name}/helpers`
      puts "#{"[Success]".green.bold} created directory!\t ./#{project_name}/helpers"
    else
      puts "Something went wrong. Exiting...".red.bold
      exit_cli
    end


    File.open("./#{project_name}/Gemfile", "w") do |f|
      f.puts "source 'https://rubygems.org'"
      f.puts "gem 'lac'"
    end
    puts "#{"[Success]".green.bold} created file!\t\t ./#{project_name}/Gemfile"

    File.open("./#{project_name}/config/lac.rb", "w") do |f|
      f.puts ""
    end
    puts "#{"[Success]".green.bold} created file!\t\t ./#{project_name}/config/lac.rb"
end

#exit_cliObject



88
89
90
91
# File 'lib/lac/cli.rb', line 88

def exit_cli
    puts "#{"\nCya!".yellow.on_black.bold}\n"
    exit
end

#prompt_input(message) ⇒ Object



82
83
84
85
86
# File 'lib/lac/cli.rb', line 82

def prompt_input(message)
    input = Readline.readline(message, true).strip
    exit_cli if input.downcase === "exit"
    return input.to_s
end

#startObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lac/cli.rb', line 15

def start
  if @action == "new"
    create_project
  elsif @action == "server"
    start_server
  else
    puts "Invalid command, exiting".red.on_white.bold
    puts "The only valid command is 'new'".green.on_white.bold
  end
  exit_cli
end

#start_serverObject



27
28
29
# File 'lib/lac/cli.rb', line 27

def start_server
  Lac::Application.run!
end