config

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddProjectPathCmd = &cobra.Command{
	Use:   "add-path [project_name]",
	Short: "Save project path to be used with start command",
	Long:  "",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		token, workspaceId, err := utils.GetConfig()
		if err != nil {
			return fmt.Errorf("failed to get configuration: %w", err)
		}

		projectName := args[0]
		currentPath, err := os.Getwd()
		if err != nil {
			return fmt.Errorf("failed to get current path: %w", err)
		}

		client := api.NewAPIClient(token)

		var projectId int
		if projectName != "" {
			projectId, err = client.GetProjectIdByName(workspaceId, projectName)
			if err != nil {
				return fmt.Errorf("failed to get project ID: %w", err)
			}
		}

		viper.Set(fmt.Sprintf("projects.%s.id", projectName), projectId)

		key := fmt.Sprintf("projects.%s.paths", projectName)
		existingPaths := viper.GetStringSlice(key)

		for _, p := range existingPaths {
			if p == currentPath {
				fmt.Println("Path already exists for this project.")
				return nil
			}
		}
		existingPaths = append(existingPaths, currentPath)

		viper.Set(key, existingPaths)

		if err := viper.WriteConfig(); err != nil {
			return fmt.Errorf("error saving configuration: %w", err)
		}

		fmt.Println("Configuration saved successfully!")
		return nil
	},
}

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