Skip to content

feat: refactor server initialization and directory creation logic#2

Merged
cfc4n merged 1 commit intomasterfrom
feat/directory-creation-logic
Mar 27, 2025
Merged

feat: refactor server initialization and directory creation logic#2
cfc4n merged 1 commit intomasterfrom
feat/directory-creation-logic

Conversation

@cfc4n
Copy link
Copy Markdown
Member

@cfc4n cfc4n commented Mar 27, 2025

No description provided.

@cfc4n cfc4n requested a review from Copilot March 27, 2025 12:55
@cfc4n cfc4n added the enhancement New feature or request label Mar 27, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the server initialization and directory creation logic to simplify the code and centralize directory creation into a single utility. Key changes include:

  • Removal of the CheckDirectory function from services/utils.go and introduction of CreateDirectory in cli/cmd/utils.go.
  • Adjustments to MoLingConfig structure and updates to directory creation logic in CLI commands (root.go, perrun.go, moling_test.go) and server initialization in moling.go.

Reviewed Changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/utils.go Removed CheckDirectory in favor of a more central directory creation logic.
services/config.go Updated MoLingConfig, adding ListenAddr and modifying BasePath comments.
cli/cmd/utils.go Introduced CreateDirectory to handle directory creation.
cli/cmd/root.go Revised pre-run logic to use the new CreateDirectory and set BasePath using the current user.
cli/cmd/perrun.go Renamed and updated pre-run function for directory creation.
cli/cmd/moling.go Updated NewMoLingServer to remove the explicit listenAddr parameter.
cli/cmd/moling_test.go Updated tests to match changes in directory creation and server initialization.
Files not reviewed (2)
  • Makefile: Language not supported
  • variables.mk: Language not supported
Comments suppressed due to low confidence (1)

cli/cmd/perrun.go:25

  • [nitpick] The function name 'mlsCommandPreFunc' is not very descriptive; consider renaming it to something like 'preRunCreateDirectories' to clarify its purpose.
func mlsCommandPreFunc(cmd *cobra.Command, args []string) error {

//rootCmd.PersistentFlags().StringSliceVar(&mlConfig.AllowDir, "allow-dir", []string{"/tmp"}, "allow dir")
rootCmd.PersistentFlags().StringVarP(&listenAddr, "listen", "l", "", "listen address,aka SSE mode. if not set, use STDIO mode")
//rootCmd.PersistentFlags().StringVarP(&mlConfig.ConfigFile, "config_file", "c", "config.json", "MoLing Config File Path")
rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.")
Copy link

Copilot AI Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base_path flag is documented as display-only, yet using a persistent flag allows its value to be overridden. Consider marking the flag as hidden or removing it to enforce read-only behavior.

Suggested change
rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.")
rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.")
rootCmd.PersistentFlags().MarkHidden("base_path")

Copilot uses AI. Check for mistakes.
@cfc4n cfc4n merged commit a9bc47c into master Mar 27, 2025
6 checks passed
@cfc4n cfc4n deleted the feat/directory-creation-logic branch March 27, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants