Module: Appril::CLI::Helpers
- Included in:
- Appril::CLI, Docker, Install, Update
- Defined in:
- lib/appril-cli/helpers.rb
Instance Method Summary collapse
- #create_dirname_for(dir) ⇒ Object
- #expanded_path(*path) ⇒ Object
- #extract_namespace(args) ⇒ Object
- #fatal_error!(*lines) ⇒ Object
- #format_error(*lines) ⇒ Object
- #make_executable(*entries) ⇒ Object
Instance Method Details
#create_dirname_for(dir) ⇒ Object
20 21 22 |
# File 'lib/appril-cli/helpers.rb', line 20 def create_dirname_for dir FileUtils.mkdir_p(File.dirname(dir)) end |
#expanded_path(*path) ⇒ Object
16 17 18 |
# File 'lib/appril-cli/helpers.rb', line 16 def *path Pathname.new(File.(File.join(*path.map(&:to_s)))) end |
#extract_namespace(args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/appril-cli/helpers.rb', line 28 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!(*lines) ⇒ Object
11 12 13 14 |
# File 'lib/appril-cli/helpers.rb', line 11 def fatal_error! *lines puts '', format_error(lines), '' exit 1 end |
#format_error(*lines) ⇒ Object
5 6 7 8 9 |
# File 'lib/appril-cli/helpers.rb', line 5 def format_error *lines lines.flatten! header = lines.shift() "\t::: %s :::%s" % [header, lines.any? ? ([''] + lines).join("\n\t") : ""] end |
#make_executable(*entries) ⇒ Object
24 25 26 |
# File 'lib/appril-cli/helpers.rb', line 24 def make_executable *entries entries.flatten.each {|e| FileUtils.chmod('+x', e)} end |