Class: Generambo::CLI::Application

Inherits:
Thor
  • Object
show all
Defined in:
lib/generambo/cli/cli.rb,
lib/generambo/cli/gen_command.rb,
lib/generambo/cli/setup_command.rb

Instance Method Summary collapse

Instance Method Details

#gen(module_name, template_folder) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generambo/cli/gen_command.rb', line 9

def gen(module_name, template_folder)
  does_generambofile_exist = Dir[GENERAMBO_FILE].count > 0

  unless does_generambofile_exist
    puts('generambofile not found! Run `generambo setup` in the working directory instead!'.colorize(:red))
    exit
  end

  setup_username_command = Generambo::CLI::SetupUsernameCommand.new
  setup_username_command.setup_username

  properties = YAML.load_file(GENERAMBO_FILE)
  properties[USERNAME_KEY] = Generambo::UserPreferences.obtain_username
  properties[CURRENT_DATE_KEY] = Time.now.strftime('%d.%m.%Y')
  properties[MODULE_NAME_KEY] = module_name

  template_folder_path = File.join(Dir.pwd, 'Templates', template_folder)
  unless File.directory?(template_folder_path)
    puts('Template does not exist!'.colorize(:red))
    exit
  end

  module_path = File.join(Dir.pwd, module_name)

  if File.directory?(module_path)
    answer = ask('The module already exists. Overwrite it? (y/n)'.colorize(:blue))
    exit unless answer == 'y'

    # remove old directory
    FileUtils.rm_rf(module_path)
  end

  # copying template files
  Generambo::Helpers::Copier.transfer(template_folder_path, module_path)

  # processing template files
  Generambo::Helpers::TemplateHandler.handle!(module_path, properties)
end

#setupObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generambo/cli/setup_command.rb', line 8

def setup
  does_generambofile_exist = Dir[GENERAMBO_FILE].count > 0

  if does_generambofile_exist
    answer = ask('Do you want to overwrite an existing generambofile? (y/n)'.colorize(:red))
    exit unless answer == 'y'
  end

  properties = {}

  setup_username_command = Generambo::CLI::SetupUsernameCommand.new
  setup_username_command.setup_username

  project_name = Pathname.new(Dir.getwd).basename.to_s
  is_right_project_name = yes?("The name of your project is #{project_name}. Do you want to use it? (yes/no)")

  properties[PROJECT_NAME_KEY] = is_right_project_name ? project_name : ask_non_empty_string('The project name:', 'Project name should not be empty')
  properties[PROJECT_PREFIX_KEY]  = ask('The project prefix (if any):')

  Generambo::GenerambofileGenerator.create_generambofile(properties)

  puts('Generambofile successful created!'.colorize(:green))
end