Module: Appril::CLI::Helpers

Included in:
Appril::CLI, App::Install, App::Update, Docker::Install, Docker::Update, Generator::API
Defined in:
lib/appril-cli/helpers.rb

Instance Method Summary collapse

Instance Method Details

#create_dirname_for(dir) ⇒ Object



18
19
20
# File 'lib/appril-cli/helpers.rb', line 18

def create_dirname_for dir
  FileUtils.mkdir_p(File.dirname(dir))
end

#display_error(error) ⇒ Object



5
6
7
# File 'lib/appril-cli/helpers.rb', line 5

def display_error error
  puts "", "\t::: #{error} :::", ""
end

#expanded_path(*path) ⇒ Object



14
15
16
# File 'lib/appril-cli/helpers.rb', line 14

def expanded_path *path
  Pathname.new(File.expand_path(File.join(*path.map(&:to_s))))
end

#extract_namespace(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/appril-cli/helpers.rb', line 30

def extract_namespace args
  return unless index = args.index('-n')
  return unless namespace = args[index + 1]
  if namespace =~ /::/
    fatal_error! "Nested namespaces not supported"
  end
  if namespace =~ /\W/
    fatal_error! "Namespace may contain only alphanumerics"
  end
  unless namespace =~ /\A[A-Z]/
    fatal_error! "Namespace should start with a capital letter"
  end
  namespace
end

#fatal_error!(error, exit_code = 1) ⇒ Object



9
10
11
12
# File 'lib/appril-cli/helpers.rb', line 9

def fatal_error! error, exit_code = 1
  display_error(error)
  exit exit_code
end

#make_executable(*entries) ⇒ Object



22
23
24
# File 'lib/appril-cli/helpers.rb', line 22

def make_executable *entries
  entries.flatten.each {|e| FileUtils.chmod('+x', e)}
end

#working_dir_opted?(opted_dir) ⇒ Boolean



26
27
28
# File 'lib/appril-cli/helpers.rb', line 26

def working_dir_opted? opted_dir
  opted_dir == '.'
end