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

A new CLI structure #112

Closed
gwennlbh opened this issue Dec 19, 2020 · 0 comments
Closed

A new CLI structure #112

gwennlbh opened this issue Dec 19, 2020 · 0 comments
Assignees
Labels
breaking-change When a feature implementation requires a MAJOR version bumps and breaks backwards compatibility

Comments

@gwennlbh
Copy link
Owner

gwennlbh commented Dec 19, 2020

Usage:
    ideaseed [options] user [PROJECT [COLUMN]] TITLE BODY
    ideaseed [options] [REPO [PROJECT [COLUMN]]] TITLE BODY
    ideaseed [options] [TITLE] BODY
    ideaseed [options] config
    ideaseed [options] logout
    ideaseed [options] login
    ideaseed [options] about | --about
    ideaseed [options] version | --version
    ideaseed [options] update

Commands:
    user                    Creates cards in your user's project. 
                            (see https://github.com/users/YOURUSERNAME/projects)
                            Flags --no-issue and --repo has no effects.
                            Flag --default-column still applies.
                            REPO is _not_ set to 'user'.
    config                  Configures an alias with Configuration flags through a series of questions.
    log(in/out)             Fills/Clears the auth cache (see --auth-cache) or the keyring (see --keyring)
    about                   Show information about ideaseed.
    version                 Outputs the version number
    update                  Check for updates. If any is available, shows the changelog. 
                            You can then decide to install the new version.
Options:
    -I --no-issue           Only creates a project card, no issue is created.
                            Has no effect when used without a REPO
    -T --title=TITLE        Specifies TITLE
    -R --repo=REPO          Specifies REPOSITORY
    -P --project=PROJECT    Specifies PROJECT
    -C --column=COLUMN      Specifies COLUMN
    -# --tag=TAG...         Add tags (GitHub) or labels (Google Keep)
                            Can be specified multiple times.
    -o --open               Open the created card (or issue) in your $BROWSER.
       --dry-run            Tell what will happen but does not do it. Still logs you in.
                            Beware, objects created with --create-missing will
                            still be created.
    -m --create-missing     Creates missing objects (projects, columns, and labels/tags)

    REPO only: 
       --self-assign        Assign the created issue to yourself. 
    -@ --assign=USER...     Assign USER to the created issue. 
                            Can be specified multiple times.
    -M --milestone=NAME...  Adds the issue to the milestone NAME.

    Google Keep only:
       --pin                Pins the card. 
       --color=COLOR        Sets the card's color. [default: white]
                            Available values: blue, brown, darkblue (or indigo), 
                            gray (or grey), green, orange, pink, purple (or magenta), 
                            red, teal (or cyan), white, yellow. 


Configuration:
   --default-column=COLUMN    Specifies the Default Column. 
                              Used when PROJECT is set but not COLUMN
   --default-project=PROJECT  Specifies the Default Project. 
                              Used when REPO is set but not PROJECT
                              If not set, or set to '<None>',
                              using REPO without PROJECT creates an issue
                              without its project card.
   --auth-cache=FILEPATH      Set the filepath for the auth. cache [default: ~/.cache/ideaseed/auth.json]
                              If set to '<None>', disables caching of credentials.
                              Cannot be used with --keyring.
   --keyring=KEYRING          Uses a system keyring instead of a cache file.
                              Cannot be used with --auth-cache.

Arguments:
    BODY      Sets the note's body. Required.
    TITLE     Sets the title.
    REPO      The repository to put the issue/card into. Uses the format [USER/]REPO. 
              If USER/ is omitted, the currently-logged-in user's username is assumed.
              Omitting this argument entirely has the effect of creating a Google Keep card instead.
              When used without PROJECT, the card is added to the Default Project (see --default-project)
    PROJECT   Specify which GitHub project to add the card to.
              When used without COLUMN, the card is added to the Default Column (see --default-column)
    COLUMN    Specify which column to use.

Some 3.10 code:

# turns docopt's parsed args into python-usable arguments for functions.
# since | updates left with right, and right only contains flags, and ARGUMENTs are normalized to arguments on the left side, this takes care of --title, --repo, --project, etc. taking precedence over TITLE, REPO, PROJECT, etc. for us!
# EDIT: Nope! None will still get merged!!!
args = { k.lower(): v for k, v in flags.items() } | { k[2:].replace('-', '_'): v for k, v in flags.items() if k.startswith('--') }

match flags:
  case {("about" | "--about"): True}:
    show_about()
  case {("version" | "--version"): True}:
    show_version()
  case {"help": True, "COMMAND": None} | {"--help": True}:
    show_help()
  case {"help": True}:
    show_command_help(**args)
  case {"config: True}:
    configure_interactively(**args)
  case {"login": True, "--keyring": None}:
    fill_auth_cache(**args)
  case {"logout": True, "--keyring": None}:
    delete_auth_cache(**args)
  case {"login": True, "--auth-cache": None}:
    add_keyring_entry(**args)
  case {"logout": True, "--auth-cache": None}:
    remove_keyring_entry(**args)
  case {"--keyring": k, "--auth-cache": c} if k and c:
    raise UsageError("--keyring and --auth-cache cannot be used simultaneously")
  case {"user": True}:
    create_user_card(**args)

# we need to match against args since here REPO and others can be specified in two ways.
match args:
  case {"repo": None}:
    if any(args['self_assign'], args['assign'], args['milestone']):
      raise UsageError(", ".join(flag for flag, is_set in flags.items() if is_set and flag in ('--self-assign', '--assign', '--milestone')) + " cannot be used without specifying a repository (use REPO or --repo)")
    create_google_keep_card(args)
  case _:
    create_github_card(args)
    if not args['no_issue']:
      create_github_issue(args)
@gwennlbh gwennlbh added the meta Stuff related to the codebase itself (refactors, formatting, etc) label Dec 19, 2020
@gwennlbh gwennlbh self-assigned this Dec 19, 2020
@gwennlbh gwennlbh changed the title Use pypi:typer for a cleaner CLI structure A new CLI structure Mar 26, 2021
@gwennlbh gwennlbh added breaking-change When a feature implementation requires a MAJOR version bumps and breaks backwards compatibility and removed meta Stuff related to the codebase itself (refactors, formatting, etc) labels Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change When a feature implementation requires a MAJOR version bumps and breaks backwards compatibility
Projects
None yet
Development

No branches or pull requests

1 participant