-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a verbose flag for displaying more messages in terminal #220
Conversation
Hey @csjones, thank you for your contribution. You've prompted a discussion on our end with this PR about whether quiet, output only commands should be the default response. That is, whether or not this should be implemented as only logging these This would then need to be rolled out across other commands so that the output of all commands is parsable by default. Did you have any other thoughts on the matter for your use case? |
I agree with @adamjcampbell here. I think the stuff like 🤔 One thing to consider is perhaps when using |
Hey @adamjcampbell @orj, I'm in favor of these changes. I think machine parsable by default and a I would propose one more additional change. When using |
@csjones sounds good to me. Are you happy to make those changes for this command / this PR? In regards to the pretty formatting of json I would think filtering out the white space would be optional. It shouldn't affect the ability to parse the JSON. However we could have it as an option or the default when not in verbose mode. What are your thoughts on the matter? |
@adamjcampbell Perhaps we can have a |
@adamjcampbell Sure! I'll make the changes and update the PR. For pretty printing output, I'm leaning towards removing Does this list of changes look good? Summary of changes:
|
@csjones sounds like a plan! Thanks for all your efforts on this. |
@@ -55,7 +55,10 @@ struct ListCertificatesCommand: CommonParsableCommand { | |||
|
|||
let file = try certificateProcessor.write($0) | |||
|
|||
print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)") | |||
// Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` | |||
if common.verbose || common.outputFormat == .table { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to have to use common.verbose || common.outputFormat == .table
quite a bit here.
What do you think about making verbose
be Bool?
(defaulting to nil
) and then we can add a computed var either a Bool or enum to check.
Thinking along these lines:
// CommonParsableCommand.swift
enum PrintLevel {
case quiet
case verbose
}
// CommonOptions
var printLevel: PrintLevel {
switch verbose {
case true:
return .verbose
case false:
return .quiet
case nil:
return common.outputFormat == .table ? .verbose : .quiet
}
}
// Usage
if common.printLevel == .verbose {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this is a good suggestion and I'll make these changes with small tweaks. I'll leave verbose
as a Bool
and I'll resolve the common.outputFormat == .table
ternary in the switch
statement itself. Should look something like this:
// CommonOptions
var printLevel: PrintLevel {
switch (verbose, outputFormat == .table) {
case (true, _), (_, true):
return .verbose
case (false, false):
return .quiet
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks @csjones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csjones This is looking ✅, just needs the swiftlint warnings attended to
🤔 Objective and Motivation
The objective of these changes are to purpose adding an optional flag
-v/--verbose
to display more output in terminal. My motivation for this flag is to remove overhead when usingasc
with ansible. I'm using the following command in my ansible playbook:...and I get the following output:
The
"stdout"
is now malformed json and requires additional parsing to work correctly by filtering out the"📥 Profile 'App Store Test001010002' downloaded to: ./aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa.mobileprovision\n"
. With the--verbose
flag added, the command now looks like this:...and I get the following output:
...and the default command and output looks like this:
...and the json returned to stdout is no longer malformed so now I get the following output:
📝 Summary of Changes
Changes proposed in this pull request:
-v/--verbose
to display more in terminal..prettyPrinted
and created Add a flag to prettify output #221Document anything here that you think the reviewer(s) of this PR may need to know, or would be of specific interest.
The
--verbose
only changes the output of aCommonParsableCommand
that has not been commented with aTODO
.🧐🗒 Reviewer Notes
💁 Example
🔨 How To Test
Run these command and notice the messaging in terminal:
Run the same commands with
-v/--verbose
added and notice more messaging in terminal: