initcmd

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package initcmd provides the command to initialize the project configuration.

Index

Constants

This section is empty.

Variables

View Source
var InitCmd = &cobra.Command{
	Use: "init",
	RunE: func(cmd *cobra.Command, _ []string) error {
		presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr())
		ctx := cmd.Context()

		presenter.Summary("Initializing ContextVibes configuration...")

		stdout, stderr, err := globals.ExecClient.CaptureOutput(
			ctx,
			".",
			"git",
			"rev-parse",
			"--show-toplevel",
		)
		if err != nil {
			presenter.Error("Failed to determine project root. Are you inside a Git repository?")
			presenter.Detail("Stderr: %s", stderr)

			return errors.New("not a git repository")
		}
		projectRoot := strings.TrimSpace(stdout)
		configPath := filepath.Join(projectRoot, config.DefaultConfigFileName)

		if _, err := os.Stat(configPath); err == nil {
			presenter.Info("Configuration file already exists: %s", presenter.Highlight(configPath))

			return nil
		}

		defaultConfig := config.GetDefaultConfig()

		if err := config.UpdateAndSaveConfig(defaultConfig, configPath); err != nil {
			return fmt.Errorf("failed to save config: %w", err)
		}

		presenter.Success("Successfully created .contextvibes.yaml.")

		return nil
	},
}

InitCmd represents the init command.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL