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): Improved the DX for list profile #334

Merged
merged 7 commits into from
Jul 17, 2024

Conversation

kriptonian1
Copy link
Contributor

@kriptonian1 kriptonian1 commented Jul 8, 2024

User description

Description

Give a summary of the change that you have made

Fixes #[ISSUENO]

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

Add screenshots of relevant screens

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, Dependencies


Description

  • Enhanced the profile listing command to use cli-table and colors for better readability.
  • Updated the prompt message in the profile creation command to specify "API key" instead of "private key".
  • Added new dependencies (cli-table, colors, chalk) and updated package.json with a new dev script.

Changes walkthrough 📝

Relevant files
Enhancement
list.profile.ts
Enhance profile listing with table format and colors         

apps/cli/src/commands/profile/list.profile.ts

  • Added cli-table and colors for enhanced table display.
  • Replaced Logger with formatted table output for profiles.
  • Improved verbose output to include API Key and Base URL.
  • +50/-13 
    create.profile.ts
    Update prompt message for API key input                                   

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

    • Changed prompt message from "private key" to "API key".
    +1/-1     
    Dependencies
    package.json
    Add dependencies and dev script for CLI enhancements         

    apps/cli/package.json

  • Added cli-table, colors, and chalk dependencies.
  • Added @types/cli-table to devDependencies.
  • Added dev script for building and running the project.
  • +10/-3   
    Additional files (token-limit)
    pnpm-lock.yaml
    ...                                                                                                           

    pnpm-lock.yaml

    ...

    +9305/-11349

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Possible Bug:
    The use of require instead of ES6 import statements in TypeScript files (list.profile.ts) might not align with the project's coding guidelines, especially if the project is using ES6 modules elsewhere.

    Code Quality:
    Inline disabling of ESLint rules (// eslint-disable-next-line) for the require statements suggests potential issues with the project's linting configuration or module resolution strategy.

    Performance Concern:
    The dynamic creation of tables and handling of profiles in the list.profile.ts might lead to performance issues if the number of profiles is large. Consider optimizing the data handling or using pagination.

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check to ensure profiles is not empty before proceeding to create and print the table

    Add a check to ensure profiles is not empty before proceeding to create and print the
    table to avoid potential runtime errors.

    apps/cli/src/commands/profile/list.profile.ts [35-37]

     const profiles = await fetchProfileConfig()
    +if (!profiles || Object.keys(profiles).length === 0) {
    +  console.log('No profiles found.')
    +  return
    +}
     const defaultProfile = profiles.default
     delete profiles.default
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses a potential runtime error which is crucial for robustness and reliability of the application, making it a highly valuable improvement.

    9
    Best practice
    Replace require statements with import statements for better consistency and type checking

    Instead of using require statements, use import statements for cli-table and colors to
    maintain consistency and leverage TypeScript's type checking.

    apps/cli/src/commands/profile/list.profile.ts [7-10]

    -// eslint-disable-next-line @typescript-eslint/no-var-requires
    -const Table = require('cli-table')
    -// eslint-disable-next-line @typescript-eslint/no-var-requires
    -const colors = require('colors/safe')
    +import Table from 'cli-table'
    +import colors from 'colors/safe'
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a best practice in TypeScript to use import instead of require for better type safety and consistency, which is crucial in a TypeScript project.

    8
    Maintainability
    Combine the creation of profileList arrays to reduce code duplication and improve readability

    Combine the creation of profileList arrays to reduce code duplication and improve
    readability.

    apps/cli/src/commands/profile/list.profile.ts [59-65]

    -const profileList = []
    -Object.keys(profiles).forEach((profile) => {
    -  profileList.push([
    -    `${defaultProfile === profile ? `${profile} ${colors.dim('(default)')}` : profile}`,
    -    `${profiles[profile].apiKey}`,
    -    `${profiles[profile].baseUrl}`
    -  ])
    -})
    +const profileList = Object.keys(profiles).map((profile) => [
    +  `${defaultProfile === profile ? `${profile} ${colors.dim('(default)')}` : profile}`,
    +  `${profiles[profile].apiKey}`,
    +  `${profiles[profile].baseUrl}`
    +])
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion improves maintainability and readability by reducing code duplication, which is beneficial but not as critical as fixing bugs or security issues.

    7

    @kriptonian1 kriptonian1 requested a review from rajdip-b July 8, 2024 18:12
    apps/cli/package.json Show resolved Hide resolved
    apps/cli/tsconfig.json Show resolved Hide resolved
    apps/cli/src/commands/profile/list.profile.ts Show resolved Hide resolved
    @rajdip-b rajdip-b changed the title feat: improved the dx for list profile feat(cli): Improved the DX for list profile Jul 17, 2024
    @rajdip-b rajdip-b merged commit 798cd7b into develop Jul 17, 2024
    3 checks passed
    @rajdip-b rajdip-b deleted the feat/cli-dx-profile-list branch July 17, 2024 17:20
    rajdip-b added a commit that referenced this pull request Jul 29, 2024
    Co-authored-by: Rajdip Bhattacharya <agentR47@gmail.com>
    rajdip-b pushed a commit that referenced this pull request Jul 29, 2024
    ## [2.3.0](v2.2.0...v2.3.0) (2024-07-29)
    
    ### 🚀 Features
    
    * **api:** Add pagination metadata to Environment module ([#382](#382)) ([9baa344](9baa344))
    * **api:** Add pagination metadata to Event module ([#394](#394)) ([60010b4](60010b4))
    * **api:** Add pagination metadata to Integration module ([#391](#391)) ([0372e36](0372e36))
    * **api:** Add pagination metadata to Project module ([#393](#393)) ([bc274fd](bc274fd))
    * **api:** Add pagination metadata to Secret module ([#389](#389)) ([c4cc667](c4cc667))
    * **api:** Add pagination metadata to Variable module ([#390](#390)) ([be6aabf](be6aabf))
    * **api:** Add pagination metadata to Workspace module  ([#387](#387)) ([a08c924](a08c924))
    * **api:** Add pagination metadata to Workspace Role module ([#388](#388)) ([d8e8f49](d8e8f49))
    * **api:** Create a paginate method ([#379](#379)) ([09576f1](09576f1))
    * **api:** Create endpoint for fetching all revisions of a [secure] ([#303](#303)) ([de2b602](de2b602))
    * **api:** Create endpoint for fetching all revisions of a variable ([#304](#304)) ([9abddc1](9abddc1))
    * **cli:** Improved the DX for list profile ([#334](#334)) ([6bff496](6bff496))
    * **platform:** Add warning sonner toast for invalid otp ([#335](#335)) ([21513f5](21513f5))
    
    ### 🐛 Bug Fixes
    
    * **cli:** Added parent directory check ([#359](#359)) ([538ea7f](538ea7f))
    * **platform:** Platform types fixes ([#374](#374)) ([8e9d9ff](8e9d9ff))
    
    ### 📚 Documentation
    
    * Added docker details in setting-things-up.md ([#358](#358)) ([ed5093a](ed5093a))
    * Update postman workspace link ([d6aba27](d6aba27))
    * Updated env and cli docs ([1213d2a](1213d2a))
    
    ### 🔧 Miscellaneous Chores
    
    * Added next backend url in .env.example ([5695254](5695254))
    * **api-client:** Added pagination structure ([a70e957](a70e957))
    * **api-client:** Fixed test script ([ad70819](ad70819))
    * **api-client:** Removed try-catch from tests in environment ([a64e48c](a64e48c))
    * **api:** Add user cache for optimization ([#386](#386)) ([8d730b5](8d730b5))
    * **api:** Alter cache rehydration interval ([f5f9eec](f5f9eec))
    * **api:** Fixed naming error in variable controller ([0c5a380](0c5a380))
    * **api:** Improve handling of edge cases for paginate module ([#402](#402)) ([8591487](8591487))
    * **api:** Minor updates to user service ([249d778](249d778))
    * **api:** Skip workspace creation when user is admin ([#376](#376)) ([13f6c59](13f6c59))
    * **ci:** Add docker check   ([#383](#383)) ([3119001](3119001))
    * **ci:** Add names to CI files ([1a7e5f6](1a7e5f6))
    * **ci:** Add validate CLI pipeline ([#373](#373)) ([a91df6c](a91df6c))
    * **ci:** Adding validate pipeline ([#372](#372)) ([23cf3b3](23cf3b3))
    * **ci:** Disabled platform and api deployments ([74d601a](74d601a))
    * **ci:** Fixed deployment scripts ([12e35db](12e35db))
    * **ci:** Fixed platform script ([d783f2a](d783f2a))
    * **CI:** Include migration deployment in API deploy pipeline ([dbd5222](dbd5222))
    * **CI:** Separated deployment and docker build jobs ([090e193](090e193))
    * **CI:** Setup inter-job dependency ([1756727](1756727))
    * **ci:** Update auto-assign.yaml ([#375](#375)) ([91e0ec1](91e0ec1))
    * **cli:** Changed objects to classes ([#306](#306)) ([c83f2db](c83f2db))
    * Removed Minio config ([8feb83a](8feb83a))
    * Updated deployment scripts and added health check in platform ([fcc1c3f](fcc1c3f))
    
    ### 🔨 Code Refactoring
    
    * **api:** Updated path of some endpoints in project controller ([9502678](9502678))
    * **api:** Updated Redis provider ([33491a1](33491a1))
    rajdip-b pushed a commit that referenced this pull request Jul 29, 2024
    ## [2.3.0](v2.2.0...v2.3.0) (2024-07-29)
    
    ### 🚀 Features
    
    * **api:** Add pagination metadata to Environment module ([#382](#382)) ([9baa344](9baa344))
    * **api:** Add pagination metadata to Event module ([#394](#394)) ([60010b4](60010b4))
    * **api:** Add pagination metadata to Integration module ([#391](#391)) ([0372e36](0372e36))
    * **api:** Add pagination metadata to Project module ([#393](#393)) ([bc274fd](bc274fd))
    * **api:** Add pagination metadata to Secret module ([#389](#389)) ([c4cc667](c4cc667))
    * **api:** Add pagination metadata to Variable module ([#390](#390)) ([be6aabf](be6aabf))
    * **api:** Add pagination metadata to Workspace module  ([#387](#387)) ([a08c924](a08c924))
    * **api:** Add pagination metadata to Workspace Role module ([#388](#388)) ([d8e8f49](d8e8f49))
    * **api:** Create a paginate method ([#379](#379)) ([09576f1](09576f1))
    * **api:** Create endpoint for fetching all revisions of a [secure] ([#303](#303)) ([de2b602](de2b602))
    * **api:** Create endpoint for fetching all revisions of a variable ([#304](#304)) ([9abddc1](9abddc1))
    * **cli:** Improved the DX for list profile ([#334](#334)) ([6bff496](6bff496))
    * **platform:** Add warning sonner toast for invalid otp ([#335](#335)) ([21513f5](21513f5))
    
    ### 🐛 Bug Fixes
    
    * **cli:** Added parent directory check ([#359](#359)) ([538ea7f](538ea7f))
    * **platform:** Platform types fixes ([#374](#374)) ([8e9d9ff](8e9d9ff))
    
    ### 📚 Documentation
    
    * Added docker details in setting-things-up.md ([#358](#358)) ([ed5093a](ed5093a))
    * Update postman workspace link ([d6aba27](d6aba27))
    * Updated env and cli docs ([1213d2a](1213d2a))
    
    ### 🔧 Miscellaneous Chores
    
    * Added next backend url in .env.example ([5695254](5695254))
    * **api-client:** Added pagination structure ([a70e957](a70e957))
    * **api-client:** Fixed test script ([ad70819](ad70819))
    * **api-client:** Removed try-catch from tests in environment ([a64e48c](a64e48c))
    * **api:** Add user cache for optimization ([#386](#386)) ([8d730b5](8d730b5))
    * **api:** Alter cache rehydration interval ([f5f9eec](f5f9eec))
    * **api:** Fixed naming error in variable controller ([0c5a380](0c5a380))
    * **api:** Improve handling of edge cases for paginate module ([#402](#402)) ([8591487](8591487))
    * **api:** Minor updates to user service ([249d778](249d778))
    * **api:** Skip workspace creation when user is admin ([#376](#376)) ([13f6c59](13f6c59))
    * **ci:** Add docker check   ([#383](#383)) ([3119001](3119001))
    * **ci:** Add names to CI files ([1a7e5f6](1a7e5f6))
    * **ci:** Add validate CLI pipeline ([#373](#373)) ([a91df6c](a91df6c))
    * **ci:** Adding validate pipeline ([#372](#372)) ([23cf3b3](23cf3b3))
    * **ci:** Disabled platform and api deployments ([74d601a](74d601a))
    * **ci:** Fixed deployment scripts ([12e35db](12e35db))
    * **ci:** Fixed platform script ([d783f2a](d783f2a))
    * **CI:** Include migration deployment in API deploy pipeline ([dbd5222](dbd5222))
    * **CI:** Separated deployment and docker build jobs ([090e193](090e193))
    * **CI:** Setup inter-job dependency ([1756727](1756727))
    * **ci:** Update auto-assign.yaml ([#375](#375)) ([91e0ec1](91e0ec1))
    * **cli:** Changed objects to classes ([#306](#306)) ([c83f2db](c83f2db))
    * Removed Minio config ([8feb83a](8feb83a))
    * Updated deployment scripts and added health check in platform ([fcc1c3f](fcc1c3f))
    
    ### 🔨 Code Refactoring
    
    * **api:** Updated path of some endpoints in project controller ([9502678](9502678))
    * **api:** Updated Redis provider ([33491a1](33491a1))
    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.

    2 participants