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

feat(cli): supports to specify environment(s) and its optional description #634

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ekadk
Copy link
Contributor

@ekadk ekadk commented Jan 16, 2025

User description

Description

Fixes #617

Add command option to specify one to multiple environments and its optional description.

The option's flag is -e (short) or --environment (long). the description of the option is Environment name(s) of the project. Default to Default.

Now the project create --help command would give this output:

$ pnpm dev:cli -- project create --help

# . . .

Creates a project
 
Arguments:
  Workspace Slug                 Slug of the workspace under which you want to create the project

Options:
  -n, --name <string>            Name of the project
  -d, --description <string>     Description of the project. Defaults to project name
  -k, --store-private-key        Store the private key in the project. Defaults to true (default: true)
  -a, --access-level <string>    Access level of the project. Defaults to PRIVATE. (choices: "GLOBAL", "PRIVATE", "INTERNAL", default: "PRIVATE")
  -e, --environment <string...>  Environment name(s) of the project. Default to Default
  -h, --help                     display help for command

How to test:

pnpm start:cli -- project create <WORKSPACE_SLUG> --base-url <BASE_URL> --api-key <API_KEY> -n <PROJECT_NAME> -e <ENVIRONMENT_NAME:ENVIRONMENT_DESCRIPTION> --environment <ENVIRONMENT2_NAME:ENVIRONMENT2_DESCRIPTION>

Example:

pnpm start:cli -- project create workspace-1-0 --base-url http://localhost:4200 --api-key ks_87eb7a747bfcd14984cb18643728defb53237d7be95f8bcf -n test-project -e "dev" --environment "stage:Environment for staging" -e "production:Environment for production"

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Image 1: Running the test command and the output in terminal
Screenshot From 2025-01-16 20-17-23

Image 2: Result in database

Screenshot From 2025-01-16 19-41-32

Image 3: Printing help of the command

Screenshot From 2025-01-16 20-30-49

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

PR Type

Enhancement


Description

  • Added support for specifying environments during project creation.

  • Introduced --environment option with optional descriptions.

  • Parsed and processed environment input into structured data.

  • Updated CLI help output to include new option.


Changes walkthrough 📝

Relevant files
Enhancement
create.project.ts
Support specifying environments with optional descriptions

apps/cli/src/commands/project/create.project.ts

  • Added --environment option to specify environments.
  • Parsed environment input into name and optional description.
  • Updated return structure to include environments data.
  • Enhanced CLI help output to reflect new functionality.
  • +20/-2   

    Need help?
  • Type /help how to ... in the comments thread for any question about Qodo Merge usage.
  • Check out the documentation for more information.
  • @ekadk ekadk changed the title feat(cli): supports to specify one to multiple environments and its o… feat(cli): supports to specify environment(s) and its optional description Jan 16, 2025
    @rajdip-b
    Copy link
    Member

    Impressive work I must say :)

    @muntaxir4 could you use this parsing style to update the rest of our code? Ideally we would want the commands options that take multiple inputs to be split up in this way

    @muntaxir4
    Copy link
    Contributor

    Impressive work I must say :)

    @muntaxir4 could you use this parsing style to update the rest of our code? Ideally we would want the commands options that take multiple inputs to be split up in this way

    Using ':' ? The projectEnvironment is having something similar to this.

    @ekadk ekadk marked this pull request as ready for review January 17, 2025 00:55
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    617 - PR Code Verified

    Compliant requirements:

    • Add support for specifying environments when creating a project via CLI
    • Allow specifying environment name and optional description in format ":"
    • Support multiple environments via --environment flag

    Requires further human verification:

    • Verify that the command works end-to-end with the example provided in the ticket
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Input Validation

    No validation is performed on environment names - should check for empty strings and invalid characters

    environments = environment.map((env: string) => {
      const split = env.split(':')
      return {
        name: split[0],
        description: split[1]
      }
    })

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Jan 17, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Validate user input to prevent invalid data from being processed
    Suggestion Impact:The commit implements part of the suggestion by trimming whitespace from environment name and description, but does not add the empty string validation

    code diff:

           environments = environment.map((env: string) => {
             const split = env.split(':')
             return {
    -          name: split[0],
    -          description: split[1]
    +          name: split[0].trim(),
    +          description: split[1]?.trim() ?? null
             }

    Add input validation to ensure environment names are not empty strings and follow
    valid format.

    apps/cli/src/commands/project/create.project.ts [113-119]

     environments = environment.map((env: string) => {
       const split = env.split(':')
    +  if (!split[0]?.trim()) {
    +    throw new Error('Environment name cannot be empty')
    +  }
       return {
    -    name: split[0],
    -    description: split[1]
    +    name: split[0].trim(),
    +    description: split[1]?.trim()
       }
     })
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion adds crucial input validation to prevent empty environment names and properly sanitizes input data, which is essential for maintaining data integrity and preventing runtime errors.

    9
    Initialize array variables with default values to prevent undefined states and maintain type consistency

    Initialize the environments variable with a default value when no environment is
    provided to ensure consistent return type.

    apps/cli/src/commands/project/create.project.ts [112-120]

    -if (environment) {
    -  environments = environment.map((env: string) => {
    -    const split = env.split(':')
    -    return {
    -      name: split[0],
    -      description: split[1]
    -    }
    +environments = environment ? environment.map((env: string) => {
    +  const split = env.split(':')
    +  return {
    +    name: split[0],
    +    description: split[1]
       })
    -}
    +} : [{ name: 'Default' }];
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential undefined state issue by providing a default environment when none is specified, which aligns with the CLI's default behavior mentioned in the help text and ensures type consistency.

    8

    @rajdip-b
    Copy link
    Member

    Impressive work I must say :)
    @muntaxir4 could you use this parsing style to update the rest of our code? Ideally we would want the commands options that take multiple inputs to be split up in this way

    Using ':' ? The projectEnvironment is having something similar to this.

    I think we are using ',' to separate the different project:environment pair. iguess it was something related to separating things using ,

    …ons and trim specified name and desc of an environment
    @ekadk
    Copy link
    Contributor Author

    ekadk commented Jan 17, 2025

    Update:

    1. Make environments required in returned object of parsedOptions
    2. Trim specified name and description of an environment

    Now, if we run command like:

    pnpm start:cli -- project create workspace-1-0 --base-url http://localhost:4200 --api-key ks_87eb7a747bfcd14984cb18643728defb53237d7be95f8bcf -n test-project -e "dev" --environment "  stage:   Environment for staging" -e "production:Environment for production"

    The parsed environments would looks like this:

    {
      environments: [
        { name: 'dev', description: null },
        { name: 'stage', description: 'Environment for staging' },
        { name: 'production', description: 'Environment for production' }
      ]
    }

    Example:

    pnpm start:cli -- project create workspace-1-0 --base-url http://localhost:4200 --api-key ks_87eb7a747bfcd14984cb18643728defb53237d7be95f8bcf -n test-project-5 -e "dev-test-5 " --environment "  stage-project-5:   Environment for staging" -e "production-project-5 :Environment for production "

    Terminal:

    Screenshot From 2025-01-17 15-42-40

    Database:

    Screenshot From 2025-01-17 15-43-08

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    CLI: Support to specify environments while creating a project
    4 participants