Class: AudioFeedManager::CommandsList
- Inherits:
-
Command
- Object
- Command
- AudioFeedManager::CommandsList
show all
- Defined in:
- lib/audio_feed_manager/cli/commands_list.rb
Instance Method Summary
collapse
Methods inherited from Command
arguments, #arguments, arguments_specification
Instance Method Details
#get(argv) ⇒ Object
21
22
23
24
25
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
|
# File 'lib/audio_feed_manager/cli/commands_list.rb', line 21
def get(argv)
name, *options = *argv
command = nil
case name
when 'init'
command = initialize_project
when 'publish'
command = publish
when 'help'
command = help
when 'feeds'
subcommand, *options = *options
name = "#{name} #{subcommand}"
case subcommand
when 'add'
command = add_feed
when 'show'
command = show_feed
when 'get-url'
command = get_feed_url
when 'update-rss'
command =
when 'list'
command = list_feeds
end
when 'audio'
subcommand, *options = *options
name = "#{name} #{subcommand}"
case subcommand
when 'add'
command = add_audio_file
end
when nil
command = help
end
raise UnknownCommand, "Unknown command: #{name}" unless command
[command, options]
end
|
#print_command_usage(command_name, subcommand_name = nil) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/audio_feed_manager/cli/commands_list.rb', line 75
def print_command_usage(command_name, subcommand_name = nil)
command, _ = get([command_name, subcommand_name].compact)
console.error "Usage: afm #{command.usage_line}"
if command.has_arguments?
console.error ""
console.error "Arguments:"
command.required_arguments.each do |arg|
console.error "\t#{arg.usage_name} - #{arg.description}"
end
command.optional_arguments.each do |arg|
console.error "\t#{arg.usage_name} (optional) - #{arg.description}"
end
command.varargs_arguments.each do |arg|
at_least_text = arg.minimum > 0 ? "(at least #{arg.minimum}) " : ""
console.error "\t#{arg.usage_name} #{at_least_text}- #{arg.description}"
end
end
end
|
#print_usage ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/audio_feed_manager/cli/commands_list.rb', line 65
def print_usage
console.error "Usage: afm <COMMAND> [options] [arguments...]"
console.error ""
console.error "Available commands:"
console.error ""
command_list.each do |command|
console.error "\t#{command.name} - #{command.description}"
end
end
|
#run(command_name: nil, subcommand_name: nil) ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/audio_feed_manager/cli/commands_list.rb', line 99
def run(command_name: nil, subcommand_name: nil)
if command_name
print_command_usage(command_name, subcommand_name)
else
print_usage
end
end
|