-
Notifications
You must be signed in to change notification settings - Fork 21
Makes the preset flag mandatory #75
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
Conversation
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
WalkthroughThe init command now marks the --preset flag as required via initCmd.MarkFlagRequired("preset"), causing the command to error and exit if --preset is omitted. Existing preset defaults and subsequent validation/generation logic remain unchanged and run only when a preset is provided. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant C as CLI init command
participant F as Flag Parser (Cobra)
participant V as isValidPreset
participant G as Generation Logic
U->>C: run `tool init [--preset X]`
C->>F: Parse flags (preset)
Note right of F: preset is marked required
alt Missing --preset
F-->>C: Required flag error
C-->>U: Exit with error (missing --preset)
else Provided --preset
C->>V: Validate preset
alt Invalid
V-->>C: Validation error
C-->>U: Exit with error (invalid preset)
else Valid
C->>G: Generate config/files
G-->>C: Success
C-->>U: Report completion
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @lllamnyp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request updates the command-line interface by making the 'preset' flag a required argument for the init command. This change ensures that users must explicitly provide a preset value when initializing, improving clarity and preventing incomplete configurations.
Highlights
- Command Line Interface: The
presetflag for theinitcommand is now a mandatory argument, ensuring users explicitly specify a preset when initializing.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to make the --preset flag mandatory. However, the current implementation has a couple of issues. First, MarkFlagRequired is ineffective for flags with a default value, which preset has. Second, the error returned by MarkFlagRequired is not handled. I've added specific comments with suggestions to address these points.
| initCmd.Flags().BoolVarP(&initCmdFlags.update, "update", "u", false, "update Talm library chart") | ||
|
|
||
| addCommand(initCmd) | ||
| initCmd.MarkFlagRequired("preset") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking a flag as required will not have the intended effect if the flag has a default value. The preset flag is defined with a default value of "generic" on line 208. Because of this, the flag will always be considered present, and MarkFlagRequired will not enforce that the user provides it.
To make this flag truly mandatory, you should remove the default value from its definition on line 208. For example:
// before
initCmd.Flags().StringVarP(&initCmdFlags.preset, "preset", "p", "generic", "specify preset to generate files")
// after
initCmd.Flags().StringVarP(&initCmdFlags.preset, "preset", "p", "", "specify preset to generate files")| initCmd.Flags().BoolVarP(&initCmdFlags.update, "update", "u", false, "update Talm library chart") | ||
|
|
||
| addCommand(initCmd) | ||
| initCmd.MarkFlagRequired("preset") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MarkFlagRequired returns an error which is not being checked. If an error occurs here (e.g., a typo in the flag name), it's a programming error and the application should fail fast. It's conventional to panic in init() functions for such setup errors.
if err := initCmd.MarkFlagRequired("preset"); err != nil {
panic(err)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pkg/commands/init.go (2)
94-99: Nil deref risk: check error before using configBundle.You write into configBundle before verifying err from GenerateConfigBundle; this can panic on error.
- configBundle, err := gen.GenerateConfigBundle(genOptions, clusterName, "https://192.168.0.1:6443", "", []string{}, []string{}, []string{}) - configBundle.TalosConfig().Contexts[clusterName].Endpoints = []string{"127.0.0.1"} - if err != nil { - return err - } + configBundle, err := gen.GenerateConfigBundle(genOptions, clusterName, "https://192.168.0.1:6443", "", []string{}, []string{}, []string{}) + if err != nil { + return err + } + configBundle.TalosConfig().Contexts[clusterName].Endpoints = []string{"127.0.0.1"}
121-129: File write errors for Chart.yaml are ignored.In both branches you don’t assign the error when writing Chart.yaml; failures are silently skipped.
- if parts[len(parts)-1] == "Chart.yaml" { - writeToDestination([]byte(fmt.Sprintf(content, clusterName, Config.InitOptions.Version)), file, 0o644) - } else { - err = writeToDestination([]byte(content), file, 0o644) - } + if parts[len(parts)-1] == "Chart.yaml" { + err = writeToDestination([]byte(fmt.Sprintf(content, clusterName, Config.InitOptions.Version)), file, 0o644) + } else { + err = writeToDestination([]byte(content), file, 0o644) + } if err != nil { return err }- if parts[len(parts)-1] == "Chart.yaml" { - writeToDestination([]byte(fmt.Sprintf(content, "talm", Config.InitOptions.Version)), file, 0o644) - } else { - err = writeToDestination([]byte(content), file, 0o644) - } + if parts[len(parts)-1] == "Chart.yaml" { + err = writeToDestination([]byte(fmt.Sprintf(content, "talm", Config.InitOptions.Version)), file, 0o644) + } else { + err = writeToDestination([]byte(content), file, 0o644) + } if err != nil { return err }Also applies to: 133-141
🧹 Nitpick comments (5)
pkg/commands/init.go (5)
206-214: Preset now “required”: handle the returned error, and consider removing the default + clarifying UX for --update.
- MarkFlagRequired returns an error; it’s safer to check it (e.g., cobra.CheckErr) so a future refactor doesn’t silently break validation.
- Since the flag is now required, keeping a default ("generic") is confusing in help and never used. Consider removing the default and surfacing valid values in the help text.
- Requiring --preset unconditionally also applies to the --update path (Cobra validates required flags before RunE). Confirm if that’s intended; if not, enforce “required unless --update” in PreRunE instead of MarkFlagRequired.
Apply:
initCmd.Flags().StringVar(&initCmdFlags.talosVersion, "talos-version", "", "the desired Talos version to generate config for (backwards compatibility, e.g. v0.8)") - initCmd.Flags().StringVarP(&initCmdFlags.preset, "preset", "p", "generic", "specify preset to generate files") + initCmd.Flags().StringVarP(&initCmdFlags.preset, "preset", "p", "", fmt.Sprintf("specify preset to generate files (one of: %s)", strings.Join(generated.AvailablePresets, ", "))) initCmd.Flags().BoolVar(&initCmdFlags.force, "force", false, "will overwrite existing files") initCmd.Flags().BoolVarP(&initCmdFlags.update, "update", "u", false, "update Talm library chart") addCommand(initCmd) - initCmd.MarkFlagRequired("preset") + cobra.CheckErr(initCmd.MarkFlagRequired("preset"))If you want “required unless --update”, drop MarkFlagRequired and add in PreRunE:
if !initCmdFlags.update && !cmd.Flags().Changed("preset") { return fmt.Errorf("--preset is required (valid: %s)", strings.Join(generated.AvailablePresets, ", ")) }Optionally add shell completion for presets (nice UX):
cobra.CheckErr(initCmd.RegisterFlagCompletionFunc("preset", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return generated.AvailablePresets, cobra.ShellCompDirectiveNoFileComp }))
71-79: Redundant re-parse and variable shadowing for versionContract.You already parse versionContract at Lines 54–58. The second block re-declares and re-parses it, shadowing the earlier variable. Just reuse the parsed value.
- if initCmdFlags.talosVersion != "" { - var versionContract *config.VersionContract - - versionContract, err = config.ParseContractFromVersion(initCmdFlags.talosVersion) - if err != nil { - return fmt.Errorf("invalid talos-version: %w", err) - } - - genOptions = append(genOptions, generate.WithVersionContract(versionContract)) - } + if initCmdFlags.talosVersion != "" { + genOptions = append(genOptions, generate.WithVersionContract(versionContract)) + }
181-184: Duplicate directory removal in updateTalmLibraryChart.You remove charts/talm twice. The second removal happens after you just wrote Chart.yaml, deleting it needlessly before the loop. Drop the second RemoveAll.
- // Remove the existing talm chart directory - if err := os.RemoveAll(talmChartDir); err != nil { - return fmt.Errorf("failed to remove existing talm chart directory: %w", err) - }
247-251: “Created …” log is printed even if the write failed.Print only on success.
- err := os.WriteFile(destination, data, permissions) - - fmt.Fprintf(os.Stderr, "Created %s\n", destination) - - return err + err := os.WriteFile(destination, data, permissions) + if err != nil { + return err + } + fmt.Fprintf(os.Stderr, "Created %s\n", destination) + return nil
87-87: Typo in comment.“Clalculate” → “Calculate”.
- // Clalculate cluster name from directory + // Calculate cluster name from directory
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
pkg/commands/init.go(1 hunks)
… flags (#386) ## Summary Update documentation to reflect breaking changes in talm from PR #75 and PR #86: - Add mandatory `--preset` flag (previously defaulted to "generic") - Add mandatory `--name` flag (previously derived from directory name) - Use different directory and cluster names to clarify they are separate concepts ## Changed files - `content/en/docs/install/kubernetes/talm.md` - `content/en/blog/2025-04-28-a-simple-way-to-install-talos-linux-on-any-machine-with-any-provider.md` - `content/en/docs/install/providers/hetzner.md` - `content/en/docs/install/providers/oracle-cloud.md` - `content/en/docs/install/providers/servers-com/_index.md` ## References - cozystack/talm#75 - cozystack/talm#86 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated Talos Linux installation documentation across multiple providers with standardized directory naming conventions for consistency. * Revised configuration initialization commands with explicit flags for preset and cluster name parameters. * Enhanced setup procedures in blog posts and provider-specific installation guides. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit