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: wsh export-config command #1641

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

weilirs
Copy link

@weilirs weilirs commented Dec 27, 2024

feat #1608
export-config [output-path] to export config files into a zip archive.

@CLAassistant
Copy link

CLAassistant commented Dec 27, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request introduces a new exportconfig command to the Wave Terminal application, allowing users to export configuration files into a zip archive. The command is implemented in the wshcmd-export-config.go file using the Cobra library and requires an output path as an argument, defaulting to a .zip file if not specified.

Key functions added include runExportConfig, which manages the command execution, zipDir, responsible for creating the zip archive by traversing the configuration directory, and getWaveConfigDir, which identifies the location of the Wave Terminal configuration directory in the user's home directory. The implementation includes error handling to address potential issues during the export process, ensuring that users receive appropriate feedback if errors occur.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
cmd/wsh/cmd/wshcmd-export-config.go (3)

15-22: Consider adding default directory logic and argument validations
Currently, the command strictly requires an output path. If the user runs wsh export-config without providing an argument, it raises an error. You could supply a default path (e.g., export.zip) and rely on cobra.ExactArgs(0) or the built-in Args validators for improved user experience.


25-27: Make error message more consistent
The error message "export-config requires an output path" is correct but might be more consistent with other CLI errors if rephrased, for example: "Error: output path is required. Usage: wsh export-config [output-path]"

- return fmt.Errorf("export-config requires an output path")
+ return fmt.Errorf("Error: output path is required. Usage: wsh export-config [output-path]")

82-88: Return an error if home directory cannot be determined
When os.UserHomeDir() fails, returning an empty string might cause confusion or errors downstream. Instead, return an error or a fallback path so that callers can handle the situation properly.

 func getWaveConfigDir() (string, error) {
   homeDir, err := os.UserHomeDir()
   if err != nil {
-    return ""
+    return "", fmt.Errorf("unable to determine user home directory: %v", err)
   }
   return filepath.Join(homeDir, ".config", "waveterm"), nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0df0c57 and 1aecb2c.

📒 Files selected for processing (1)
  • cmd/wsh/cmd/wshcmd-export-config.go (1 hunks)
🔇 Additional comments (1)
cmd/wsh/cmd/wshcmd-export-config.go (1)

43-59: Preserve directory structure within the zip
The current approach skips subdirectories by immediately returning nil if info.IsDir(). This won’t add empty subdirectories to the archive. While this may be acceptable, confirm whether you want to preserve the directory hierarchy in the generated zip.

cmd/wsh/cmd/wshcmd-export-config.go Outdated Show resolved Hide resolved
cmd/wsh/cmd/wshcmd-export-config.go Outdated Show resolved Hide resolved
@weilirs
Copy link
Author

weilirs commented Dec 30, 2024

I added a check for the existence of config directory, please take a look

@esimkowitz
Copy link
Member

Looks good to me! Can you add documentation to the wsh-reference.mdx file for your new command?

@weilirs
Copy link
Author

weilirs commented Dec 30, 2024

Looks good to me! Can you add documentation to the wsh-reference.mdx file for your new command?

I added to the documentation and I modified the command from export-config to exportconfig for consistency.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c59ab85 and 9011102.

📒 Files selected for processing (2)
  • cmd/wsh/cmd/wshcmd-export-config.go (1 hunks)
  • docs/docs/wsh-reference.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/wsh/cmd/wshcmd-export-config.go

Comment on lines +156 to +164
## exportconfig

You can export your Wave's config files into a zip archive using this command.

```
wsh exportconfig [output-path]
```

---
Copy link

@coderabbitai coderabbitai bot Dec 30, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance documentation for the exportconfig command.

While the basic documentation is clear, it would be more helpful to users if it included:

  1. Default behavior when no output path is specified
  2. List of configuration files that get included in the zip
  3. Usage examples
  4. Any available command flags/options

Consider expanding the documentation like this:

 ## exportconfig
 
-You can export your Wave's config files into a zip archive using this command.
+You can export your Wave Terminal's configuration files into a zip archive. This is useful for backing up your settings or transferring them to another machine.
 

wsh exportconfig [output-path]

+
+If no output path is specified, it defaults to `wave-config-<timestamp>.zip` in the current directory.
+
+The exported archive includes:
+- settings.json
+- presets.json
+- widgets.json
+- AI presets
+- Other configuration files
+
+Examples:
+```bash
+# Export to the default location
+wsh exportconfig
+
+# Export to a specific file
+wsh exportconfig ~/backups/wave-config.zip
+
+# Export to a specific directory (filename will be auto-generated)
+wsh exportconfig ~/backups/
+```

Copy link
Member

Choose a reason for hiding this comment

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

good suggestion @weilirs

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@weilirs weilirs requested a review from esimkowitz December 31, 2024 14:45
})
}

func getWaveConfigDir() string {
Copy link
Member

Choose a reason for hiding this comment

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

This is not reliable as the user may have a different config directory defined, such as on dev where it's ~/.config/waveterm-dev. You should use wavebase.GetWaveConfigDir instead.

Copy link
Member

@esimkowitz esimkowitz Jan 1, 2025

Choose a reason for hiding this comment

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

However, because this is called from the wsh side, which doesn't have the environment variables defined, you should instead call the wshclient.PathCommand function, since that will get you whatever the value is in wavesrv

Copy link
Member

Choose a reason for hiding this comment

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

actually, this won't work at all if you're on a remote machine. The logic for zipping the config should be moved to wavesrv and called through the wshserver mechanism, you can look at the other commands to see how we do this. Then, if the user is invoking this command from a remote machine, we should copy the zipped archive to the output path on the remote machine

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

Successfully merging this pull request may close these issues.

3 participants