Skip to content

Commit d7e8b68

Browse files
authored
Merge pull request #48 from nazwr/15-add---quiet-option-when-running-to-suppress-logging
15 add quiet option when running to suppress logging
2 parents b845d3f + 8c74182 commit d7e8b68

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ With Deadlist, you can download audio files in any of the formats available, reg
2222
| Directory | -d, --directory | Custom download location. Defaults to ./shows |
2323
| Help | -h, --help | Show help documentation |
2424
| Version | -v, --version | Show version of DeadList |
25+
| Quiet | -q, --quiet | Suppresses logger output for run |
2526

2627

2728
### Advanced Usage

features/cli_integration.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,15 @@ Feature: End-to-end CLI integration
7676
And it should create the show successfully
7777
And it should display "Test Download, skipping" message
7878
And the process should complete without downloads
79+
80+
Scenario: Run with --quiet flag suppresses info messages
81+
Given I have valid arguments "--id gd1977-05-08 --format mp3 --quiet"
82+
When I run the DeadList CLI
83+
Then it should not display the startup banner
84+
And it should not display info messages
85+
86+
Scenario: Quiet mode still shows errors
87+
Given I have arguments with invalid show ID "--id invalid-show --format mp3 --quiet"
88+
When I run the DeadList CLI with error handling
89+
Then it should display a scraping error message
90+
And it should not display the startup banner

features/step_definitions/cli_integration_steps.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ def with_argv(args)
293293
# No download errors, but also no actual downloads
294294
expect(@output).not_to include("Download failed")
295295
end
296+
297+
Then('it should not display the startup banner') do
298+
expect(@output).not_to include("One man gathers what another man spills")
299+
expect(@output).not_to include("=" * 52)
300+
end
301+
302+
Then('it should not display info messages') do
303+
expect(@output).not_to include("tracks found")
304+
expect(@output).not_to include("💿")
305+
end

lib/deadlist.rb

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,37 @@ class DeadList
1111
attr_reader :current_version
1212

1313
def initialize(logger: Logger.new($stdout))
14-
@logger = logger
15-
@logger.level = Logger::INFO
16-
@logger.formatter = proc do |severity, datetime, progname, msg|
14+
@logger = logger
15+
@logger.level = Logger::INFO # Default level
16+
@logger.formatter = proc do |severity, datetime, progname, msg|
1717
"#{msg}\n"
18-
end
19-
@current_version = VERSION
18+
end
19+
@current_version = VERSION
2020
end
2121

2222
# Argument abstraction should probably happen at this level!
2323

2424
def run(argv = ARGV)
25-
# Start a new CLI session
26-
# In future this could be abstracted to pass the show link vs all args, so a 'session' is started per show.
27-
session = CLI.new(@current_version, argv, logger: @logger)
28-
29-
# Scrape links and metadata for given show
30-
session.create_show
31-
32-
# In future, consider starting multiple downloaders for a list of shows
33-
# show_list = session.args[:shows]
34-
# show_list.each do |show|
35-
# session.download_show(show)
36-
# end
37-
38-
# Create folder with show date and begin track downloads if format matches
39-
session.download_show
25+
# Check for --quiet flag and adjust logger level
26+
if argv.include?('--quiet') || argv.include?('-q')
27+
@logger.level = Logger::ERROR
28+
end
29+
30+
# Start a new CLI session
31+
# In future this could be abstracted to pass the show link vs all args, so a 'session' is started per show.
32+
session = CLI.new(@current_version, argv, logger: @logger)
33+
34+
# Scrape links and metadata for given show
35+
session.create_show
36+
37+
# In future, consider starting multiple downloaders for a list of shows
38+
# show_list = session.args[:shows]
39+
# show_list.each do |show|
40+
# session.download_show(show)
41+
# end
42+
43+
# Create folder with show date and begin track downloads if format matches
44+
session.download_show
4045
end
4146
end
4247

lib/deadlist/cli/argument_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def self.parse(args, version)
3131
puts "deadlist v#{version}"
3232
exit
3333
end
34+
35+
opts.on('-q', '--quiet', 'Run silently') do
36+
params[:quiet] = true
37+
end
3438
end
3539

3640
parser.parse!(args)

0 commit comments

Comments
 (0)