Class: Vanagon::CLI::List
- Inherits:
-
Vanagon::CLI
- Object
- Vanagon::CLI
- Vanagon::CLI::List
- Defined in:
- lib/vanagon/cli/list.rb
Constant Summary collapse
- DOCUMENTATION =
<<~DOCOPT.freeze Usage: list [options] Options: -h, --help Display help -c, --configdir DIRECTORY Configuration directory [default: #{Dir.pwd}/configs] -d, --defaults Display the list of default platforms -l, --platforms Display a list of platforms -r, --projects Display a list of projects -s, --use-spaces Displays the list as space separated DOCOPT
Instance Method Summary collapse
- #check_directories(options) ⇒ Object
- #options_translate(docopt_options) ⇒ Object
- #output(list, use_spaces) ⇒ Object
- #parse(argv) ⇒ Object
-
#run(options) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #topic_list(*topic_path_items) ⇒ Object
Methods inherited from Vanagon::CLI
Instance Method Details
#check_directories(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vanagon/cli/list.rb', line 61 def check_directories() platforms_directory = File.join([:configdir], 'platforms') projects_directory = File.join([:configdir], 'projects') unless Dir.exist?(platforms_directory) VanagonLogger.error "Platforms directory \"#{platforms_directory}\" does not exist." exit 1 end unless Dir.exist?(projects_directory) VanagonLogger.error "Projectss directory \"#{projects_directory}\" does not exist." exit 1 end end |
#options_translate(docopt_options) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vanagon/cli/list.rb', line 82 def () translations = { '--configdir' => :configdir, '--defaults' => :defaults, '--platforms' => :platforms, '--projects' => :projects, '--use-spaces' => :use_spaces, } return .map { |k, v| [translations[k], v] }.to_h end |
#output(list, use_spaces) ⇒ Object
27 28 29 30 |
# File 'lib/vanagon/cli/list.rb', line 27 def output(list, use_spaces) return list.join(' ') if use_spaces return list end |
#parse(argv) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/vanagon/cli/list.rb', line 20 def parse(argv) Docopt.docopt(DOCUMENTATION, { argv: argv }) rescue Docopt::Exit => e VanagonLogger.error e. exit 1 end |
#run(options) ⇒ Object
rubocop:disable Metrics/AbcSize
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 |
# File 'lib/vanagon/cli/list.rb', line 32 def run() # rubocop:disable Metrics/AbcSize check_directories() default_list = topic_list(File.dirname(__FILE__), '..', 'platform', 'defaults') platform_list = topic_list([:configdir], 'platforms') project_list = topic_list([:configdir], 'projects') if [:defaults] puts "- Defaults", output(default_list, [:use_spaces]) return end if [:projects] == [:platforms] puts "- Projects", output(project_list, [:use_spaces]), "\n", "- Platforms", output(platform_list, [:use_spaces]) return end if [:projects] puts "- Projects", output(project_list, [:use_spaces]) return end if [:platforms] puts "- Platforms", output(platform_list, [:use_spaces]) return end end |
#topic_list(*topic_path_items) ⇒ Object
76 77 78 79 80 |
# File 'lib/vanagon/cli/list.rb', line 76 def topic_list(*topic_path_items) Dir.children(File.join(topic_path_items)).map do |t| File.basename(t, File.extname(t)) end.sort end |