-
Notifications
You must be signed in to change notification settings - Fork 550
Hide overrides key if empty, display comment for flags if empty #7986
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
Changes from all commits
e2ea573
ad913b2
4ded49f
03744b6
4767835
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import yaml from "js-yaml"; | ||
|
||
interface IYAMLError { | ||
name: string; | ||
reason: string; | ||
line: string; | ||
} | ||
|
||
const constructErrorString = (yamlError: IYAMLError) => { | ||
export const constructErrorString = (yamlError: IYAMLError) => { | ||
return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`; | ||
}; | ||
|
||
export const agentOptionsToYaml = (agentOpts: any) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any chance of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this was done (or meant to be done, I guess) at the callsite with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont have the best typing in some parts of the app atm. I'd look at where this code is used to determine if that's a possiblity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the check inside the func. Regarding the type, |
||
agentOpts ||= {}; | ||
|
||
// hide the "overrides" key if it is empty | ||
if (!agentOpts.overrides || Object.keys(agentOpts.overrides).length === 0) { | ||
delete agentOpts.overrides; | ||
} | ||
|
||
// add a comment besides the "command_line_flags" if it is empty | ||
let addFlagsComment = false; | ||
if ( | ||
!agentOpts.command_line_flags || | ||
Object.keys(agentOpts.command_line_flags).length === 0 | ||
) { | ||
// delete it so it does not render, and will add it explicitly after (along with the comment) | ||
delete agentOpts.command_line_flags; | ||
addFlagsComment = true; | ||
} | ||
|
||
let yamlString = yaml.dump(agentOpts); | ||
if (addFlagsComment) { | ||
yamlString += "command_line_flags: {} # requires Orbit\n"; | ||
} | ||
|
||
return yamlString; | ||
}; | ||
|
||
export default constructErrorString; |
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.
Should we have the same
|| {}
(presumably inside the parens) here too?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.
if
yaml.dump
gracefully handles falsey values, I'd be inclined to just leave it like this. Otherwise yes, I vote to add the safety|| {}
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.
I ended up moving the check inside
agentOptionsToYaml
instead.