Class: XCApp::CreateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/xcapp/create_command.rb

Instance Method Summary collapse

Instance Method Details

#ask_for_bundle_identifier(project_name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/xcapp/create_command.rb', line 28

def ask_for_bundle_identifier project_name
  guessed_bundle_id = guess_bundle_identifier project_name
  prompt = "Bundle identifier (e.g. com.company.#{project_name}): "

  if guessed_bundle_id
    ask(prompt) { |q| q.default = guessed_bundle_id }
  else
    ask prompt
  end
end

#ask_for_languageObject



39
40
41
# File 'lib/xcapp/create_command.rb', line 39

def ask_for_language
  choose_inline 'Language for the app? ', ProjectCreator::SUPPORTED_LANGUAGES, :swift
end

#ask_for_project_nameObject



19
20
21
22
23
24
25
26
# File 'lib/xcapp/create_command.rb', line 19

def ask_for_project_name
  name = ask('App name: ')
  while !name or name.length == 0
    name = ask('You must input a name for the app: ')
  end

  name
end

#create_project_directory(project_name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/xcapp/create_command.rb', line 53

def create_project_directory project_name
  if Dir.exists? project_name
    overwrite = agree("#{project_name} directory already exist, overwrite? (yes/no) ") { |q| q.default = 'no' }
    XCApp.exit_gracefully nil unless overwrite

    FileUtils.rm_rf project_name
  end

  FileUtils.mkdir_p project_name
end

#guess_bundle_identifier(project_name) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/xcapp/create_command.rb', line 43

def guess_bundle_identifier project_name
  git_user_email = Helper::GitHelper.get_current_user_email
  return nil unless git_user_email

  domain = git_user_email.partition('@').last.chomp
  return nil unless (domain and domain.length > 0)

  domain.split('.').reverse.join('.') + ".#{project_name}"
end

#run(name, bundle_identifier, language) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/xcapp/create_command.rb', line 7

def run name, bundle_identifier, language
  name              = ask_for_project_name unless name
  bundle_identifier = ask_for_bundle_identifier name unless bundle_identifier
  language          = ask_for_language     unless language

  create_project_directory name

  creator = ProjectCreator.new
  creator.create_project name, name, bundle_identifier, language.to_sym
  say "Project created."
end