Adds explicit search command for better UX by scalvert · Pull Request #2 · gleanwork/glean-cli

Summary

⚠️ This PR got WAAAAAAAY out of control in terms of size, and I probably should have split it up, but 🤷‍♂️ .

Adds a glean search ... command to provide a better UX to perform searches. This command wraps our existing http client implementation and uses that to load config, perform search, etc. Most of the code relates to providing types for marshaling/unmarshaling.

Screenshot 2025-01-30 at 7 54 24 AM

This pull request includes significant refactoring and improvements to the command structure of the CLI. The changes focus on improving code maintainability by converting existing command functions to use a more consistent and modular approach.

Refactoring and Improvements:

  • Command Structure Refactoring:

    • cmd/api.go: Renamed apiOptions to APIOptions, updated function names to follow Go naming conventions, and removed the init function in favor of returning the command from NewCmdAPI. [1] [2] [3] [4]
    • cmd/config.go: Introduced ConfigOptions struct, replaced var configCmd with NewCmdConfig function, and updated flag handling to use the new struct. [1] [2] [3] [4]
    • cmd/generate.go: Replaced var generateCmd with NewCmdGenerate function.
    • cmd/openapi_spec.go: Introduced OpenAPISpecOptions struct, replaced newOpenapiSpecCmd with NewCmdOpenAPISpec function, and updated flag handling to use the new struct. [1] [2] [3]
  • Test Updates:

    • cmd/api_test.go: Adjusted tests to use the new NewCmdAPI function and removed redundant test cases.
    • cmd/config_test.go: Updated tests to use the new NewCmdConfig function and simplified test cases.
    • cmd/generate_test.go: Adjusted tests to use the new NewCmdGenerate function.
    • cmd/openapi_spec_test.go: Updated tests to use the new NewCmdOpenAPISpec function, removed mock client setup, and simplified test case structure. [1] [2] [3]
  • Root Command Update:

    • cmd/root.go: Introduced NewCmdRoot function to create the root command, replacing the previous var rootCmd.