Skip to content
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

Add argument & command validation in scope of repo #234

Merged
merged 4 commits into from
Aug 23, 2023
Merged

Conversation

mordamax
Copy link
Contributor

Closes #233
Tested locally
image

Also added validation of commands & subcommands in scope of repo - will fail with related message

@mordamax mordamax requested a review from a team as a code owner August 22, 2023 17:59
@@ -38,6 +39,38 @@ export function getCommanderFromConfiguration(
let parsedCommand: ParseResults["parsedCommand"] = undefined;
const helpStr = `Refer to [help docs](${docsPath}) and/or [source code](${config.pipelineScripts.repository}).`;

const exitOverride = (commandKey: string) => (e: CommanderError) => {
if (e.code === "commander.excessArguments") {
throw new Error(((e as CommanderError).message = `Unknown subcommand of "${commandKey}". ${helpStr}`));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding the intentions here. Are we changing one error's message and throwing another new error?
Would it make sense to do instead:

throw new Error(`Unknown subcommand of "${commandKey}". ${helpStr}`);

or

(e as CommanderError).message = `Unknown subcommand of "${commandKey}". ${helpStr}`;

throw e;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, by the looks of it

throw new Error(((e as CommanderError).message = `Unknown subcommand of "${commandKey}". ${helpStr}`));

is equivalent to

throw new Error(`Unknown subcommand of "${commandKey}". ${helpStr}`);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha i just copied from the bottom one, and refactored in really ugly way not even thinking 😂😂

thanks, fixed!

Cancel cases
*/
Cancel cases
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatic formatting with IDEA? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most probably :)

src/command-configs/utils.ts Outdated Show resolved Hide resolved
@@ -38,6 +39,38 @@ export function getCommanderFromConfiguration(
let parsedCommand: ParseResults["parsedCommand"] = undefined;
const helpStr = `Refer to [help docs](${docsPath}) and/or [source code](${config.pipelineScripts.repository}).`;

const exitOverride = (commandKey: string) => (e: CommanderError) => {
if (e.code === "commander.excessArguments") {
throw new Error(((e as CommanderError).message = `Unknown subcommand of "${commandKey}". ${helpStr}`));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, by the looks of it

throw new Error(((e as CommanderError).message = `Unknown subcommand of "${commandKey}". ${helpStr}`));

is equivalent to

throw new Error(`Unknown subcommand of "${commandKey}". ${helpStr}`);

mordamax and others added 3 commits August 23, 2023 13:08
Co-authored-by: Yuri Volkov <0@mcornholio.ru>
Signed-off-by: Maksym H <1177472+mordamax@users.noreply.github.com>
@mordamax mordamax merged commit a50ccde into master Aug 23, 2023
2 checks passed
@mordamax mordamax deleted the mak-fix-commands branch August 23, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unknown preset is silently defaulted to a root command and sends wrong default attributes
3 participants