mirror of
https://github.com/yarlson/lnk.git
synced 2025-08-31 18:01:41 +02:00
feat: add --remote flag to init command for adding origin remote
This commit is contained in:
14
cmd/init.go
14
cmd/init.go
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user