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

Bug: Invalid option choice! with multiple required options that have predefined choices #50

Open
martin-braun opened this issue Jun 24, 2023 · 3 comments

Comments

@martin-braun
Copy link

martin-braun commented Jun 24, 2023

Hi, I have two mandatory actions, but Denomander seems to get confused about what the right choices are, it mixes things up. Did I find a bug?

import { default as Denomander, Option as DenomanderOption } from "https://deno.land/x/[email protected]/mod.ts";

const projectActions: string[] = [
  "clone",
  "reset",
  "flavor",
  "clean",
  "prepare",
  "build",
  "tag",
  "release",
  "exec",
  "wipe",
];

const projectNames: string[] = [
  "core",
  "explorer",
  "wallet",
  "desktop",
  "android",
  "ios",
];

program
  .command("proj", "Executes a given action on a project.")
  .option(
    "-s --slug",
    "Execute the action on a different slug than provided in the env configuration. (optional)"
  )
  .option(
    "-b --base-slug",
    "Execute the action from a different slug origin than provided in the env configuration. (optional)"
  )
  .addOption(
    new DenomanderOption({
      flags: "-a --action",
      description: "Action to execute.",
      isRequired: true,
    }).choices(projectActions)
  )
  .addOption(
    new DenomanderOption({
      flags: "-n --name",
      description: "Name of the project.",
      isRequired: true,
    }).choices([...projectNames, "all"])
  )
  .action(async () => {
  });

program.parse(Deno.args);
> deno run ./demo.ts proj -a flavor -n core
❌ Error (a): Invalid option choice! Argument 'flavor' is invalid. Allowed choices are: core,explorer,wallet,desktop,android,ios,all

@siokas Am I missing something?

@martin-braun martin-braun changed the title Invalid option choice! with multiple required options Bug: Invalid option choice! with multiple required options that have predefined choices Jun 24, 2023
@martin-braun
Copy link
Author

Ok moving choices into the constructor of Option solved the issue. I think there is a bug in the choices method implementation.

@martin-braun
Copy link
Author

It's probably, because action is conflicting with action of Denomander, I will pick something else. Maybe throwing an error when trying to use a reserved name? Still annoying, that I can't use action as option ...

@Bleeky
Copy link

Bleeky commented Apr 9, 2024

Facing the same issue here. The validation process does not work when using the Option class directly with the addOption() method.

import Denomander, { Option } from "https://deno.land/x/denomander/mod.ts";

const program = new Denomander({
    app_name: "Organisation manager",
    app_description: "Manage organisations.",
    app_version: "1.0.0",
});

const countries = new Option({
    flags: "-c --country",
    description: "Define country for which the number should be purchased.",
}).choices(["NL", "US"]);
const email = new Option({
    flags: "-e --email",
    description: "Define the email of owner.",
}).isRequired(true);

program
    .command("create-org", "Creates a new organisation.")
    .addOption(email)
    .addOption(countries)
    .action(({ args }: any) => {
        console.log(args);
    });

program.parse(Deno.args);

1. Error when running the script

deno run cli/organisation.ts create-org -e "[email protected]" -c "NL"
❌ Error (e): Invalid option choice! Argument '[email protected]' is invalid. Allowed choices are: NL,US

2. Error with the help, does not show required parameters

deno run cli/organisation.ts create-org --help

Command Usage:
create-org {options}

Description:
Creates a new organisation.

Options:
-c --country Define country for which the number should be purchased.	(choices: NL,US)
-e --email   Define the email of owner.
-h --help    Help Screen

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

No branches or pull requests

2 participants