feat: add --remote flag to init command for adding origin remote

This commit is contained in:
Yar Kravtsov
2025-05-24 06:26:43 +03:00
parent 9e1f834131
commit f640d6d11e
5 changed files with 71 additions and 1 deletions

View File

@@ -12,15 +12,27 @@ var initCmd = &cobra.Command{
Short: "Initialize a new lnk repository",
Long: "Creates the lnk directory and initializes a Git repository for managing dotfiles.",
RunE: func(cmd *cobra.Command, args []string) error {
remote, _ := cmd.Flags().GetString("remote")
lnk := core.NewLnk()
if err := lnk.Init(); err != nil {
return fmt.Errorf("failed to initialize lnk: %w", err)
}
fmt.Println("Initialized lnk repository")
if remote != "" {
if err := lnk.AddRemote("origin", remote); err != nil {
return fmt.Errorf("failed to add remote: %w", err)
}
fmt.Printf("Initialized lnk repository with remote: %s\n", remote)
} else {
fmt.Println("Initialized lnk repository")
}
return nil
},
}
func init() {
initCmd.Flags().StringP("remote", "r", "", "Add origin remote URL to the repository")
rootCmd.AddCommand(initCmd)
}