Class: Commandly::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Set exit code of failing command if failure

Returns:

  • (Boolean)


9
10
11
# File 'lib/commandly/cli.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#new(project_name) ⇒ Object

Raises:

  • (Error)


26
27
28
29
30
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
# File 'lib/commandly/cli.rb', line 26

def new(project_name)
  project_path = File.expand_path(project_name)
  raise Error, set_color("ERROR: #{project_path} already exists.", :red) if File.exist?(project_path)

  generator = Commandly::Generator.new
  generator.destination_root = project_path
  remote = false

  if options[:templateURL]
    remote = true
    say "Git cloning from git repository: #{options[:templateURL]}"
    Git.clone(options[:templateURL], project_path)
    # Remove .git directory
    `rm -rf #{project_path}/.git`
  end

  if options[:ios]
    say "Creating iOS project at #{project_path}"
    generator.invoke(:copy_ios_templates) unless remote
    generator.invoke(:find_replace_ios_text)
    generator.invoke(:rename_ios_files)
    `rm -rf #{project_path}/android` unless options[:android]
  end

  if options[:android]
    say "Creating Android project at #{project_path}"
    generator.invoke(:copy_android_templates) unless remote
    generator.invoke(:find_replace_android_text)
    generator.invoke(:rename_android_files)
    `rm -rf #{project_path}/ios` unless options[:ios]
  end

  if options[:ios].nil? && options[:android].nil?
    say "Creating iOS and Android project at #{project_path}"
    generator.invoke(:copy_ios_templates) unless remote
    generator.invoke(:find_replace_ios_text)
    generator.invoke(:rename_ios_files)
    generator.invoke(:copy_android_templates) unless remote
    generator.invoke(:find_replace_android_text)
    generator.invoke(:rename_android_files)
  end
end

#versionObject



18
19
20
# File 'lib/commandly/cli.rb', line 18

def version
  say "commandly v#{Commandly::VERSION}"
end