Documentation
¶
Overview ¶
Package dotfiles provides cobra commands for managing user dotfiles via a bare git repository.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DotfilesCmd = &cobra.Command{ Use: "dotfiles", Short: "Manage dotfiles", Long: `This command is used to facilitate the management of private hidden dot files.`, Run: func(cmd *cobra.Command, args []string) { showInfo, _ := cmd.Flags().GetBool("info") isVerbose := utils.IsVerbose(cmd) if showInfo { log.Info("Current dotfiles configuration:") repoPath := os.ExpandEnv(viper.GetString("dotfiles.repoPath")) worktreePath := os.ExpandEnv(viper.GetString("dotfiles.worktree")) if repoPath == "" { log.Warn(" Repository Path (dotfiles.repoPath): Not Set") } else { log.Info(" Repository Path (dotfiles.repoPath): %s", repoPath) } if worktreePath == "" { log.Warn(" Worktree Path (dotfiles.worktree): Not Set") } else { log.Info(" Worktree Path (dotfiles.worktree): %s", worktreePath) } return } if len(args) == 0 { log.Verbose(isVerbose, "No subcommand provided, showing help.") err := cmd.Help() cobra.CheckErr(err) } else { log.Verbose(isVerbose, "Subcommand '%s' provided.", args[0]) } }, }
DotfilesCmd serves as the base command for all dotfiles related operations. It doesn't perform any action itself but groups subcommands like sync and fetch.
View Source
var FetchCmd = &cobra.Command{ Use: "fetch", Short: "fetch your local bare repository", Long: `This command fetches remote changes to the local bare dot repository.`, Run: func(cmd *cobra.Command, args []string) { log.Start("Fetching dotfiles") repoPath := os.ExpandEnv(viper.GetString("dotfiles.repoPath")) if repoPath == "" { log.Error("dotfiles.repoPath is not set or resolves to an empty string in the configuration file") return } worktreePath := os.ExpandEnv(viper.GetString("dotfiles.worktree")) if worktreePath == "" { log.Error("dotfiles.worktree is not set or resolves to an empty string in the configuration file") return } err := fetchRepo(repoPath, worktreePath) if err != nil { log.Error("Failed to fetch dotfiles: %s", err) return } log.Success("Dotfiles fetched successfully") }, }
FetchCmd defines the cobra command for fetching the dotfiles repository. It only fetches remote changes without merging them.
View Source
var SyncCmd = &cobra.Command{ Use: "sync", Short: "sync your local bare repository", Long: `This command fetches and pulls in remote changes to the local bare dot repository.`, Run: func(cmd *cobra.Command, args []string) { log.Start("Syncing dotfiles") isVerbose := utils.IsVerbose(cmd) repoPath := viper.GetString("dotfiles.repoPath") repoPath = os.ExpandEnv(repoPath) if repoPath == "" { log.Error("dotfiles.repoPath is not set or resolves to an empty string in the configuration file") return } log.Verbose(isVerbose, "dotfiles.repoPath: %s", repoPath) worktreePath := viper.GetString("dotfiles.worktree") worktreePath = os.ExpandEnv(worktreePath) if worktreePath == "" { log.Error("dotfiles.worktree is not set in the configuration file") return } log.Verbose(isVerbose, "dotfiles.worktree: %s", worktreePath) log.Info("Fetching dotfiles") err := fetchRepo(repoPath, worktreePath) if err != nil { log.Error("Failed to fetch dotfiles: %s", err) return } log.Info("Pulling dotfiles with rebase") err = pullRebaseRepo(repoPath, worktreePath) if err != nil { log.Error("Failed to pull and rebase dotfiles: %s", err) return } log.Success("Dotfiles synced successfully") }, }
SyncCmd defines the cobra command for syncing the dotfiles repository. It fetches remote changes and then performs a pull with rebase.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.