Class: Morpheus::Cli::CatCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/standard/cat_command.rb

Overview

This is for printing the content of files(s)

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#handle(args) ⇒ 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
# File 'lib/morpheus/cli/commands/standard/cat_command.rb', line 9

def handle(args)
  append_newline = true
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name} [file ...]"
    build_common_options(opts, options, [])
    opts.footer = "Concatenate and print files." + "\n" +
                  "[file] is required. This is the name of a file. Supports many [file] arguments."
  end
  optparse.parse!(args)
  if args.count < 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "#{command_name} expects 1-N arguments and received #{args.count} #{args}\n#{optparse}"
    return 1
  end

  arg_files = args
  arg_files.each do |arg_file|
    arg_file = File.expand_path(arg_file)
    if !File.exists?(arg_file)
      print_error Morpheus::Terminal.angry_prompt
      puts_error  "#{command_name}:  file not found: '#{arg_file}'"
      #print_red_alert "morpheus cat: file not found: '#{arg_file}'"
      return 1
    end
    if File.directory?(arg_file)
      print_red_alert "morpheus cat: file is a directory: '#{arg_file}'"
      return 1
    end
    file_contents = File.read(arg_file)
    print file_contents.to_s
    return 0
  end
  return true
end