Init

Creates a new Git repository at ~/.local/share/freckles.

var initCmd = &cobra.Command{
	Use:   "init",
	Short: "init freckles folder",
	RunE: func(cmd *cobra.Command, args []string) error {
		c := exec.Command("git", "init", freckles.Dir())
		if cmd.Flag("clone").Changed {
			c = exec.Command("git", "clone", cmd.Flag("clone").Value.String(), freckles.Dir())
		}
		c.Stdin = os.Stdin
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		if err := c.Run(); err != nil {
			return err
		}

		if _, err := os.Stat(freckles.Dir() + ".frecklesignore"); os.IsNotExist(err) {
			return os.WriteFile(freckles.Dir()+".frecklesignore", []byte(".git\n.frecklesignore\n"), os.ModePerm)
		}
		return nil
	},
}

Clone

Alternatively an existing remote repository can be cloned with the --clone flag.

Completion is provided with ActionRepositorySearch.

	carapace.Gen(initCmd).FlagCompletion(carapace.ActionMap{
		"clone": spec.ActionMacro("$carapace.tools.git.RepositorySearch"),
	})

Here, carapace is invoked with the macro tools.git.RepositorySearch and the current value:

carapace _carapace macro tools.git.RepositorySearch https://github.com/rsteube/do

Which then returns the completion in the Export format.

{
  "version": "v1.8.0",
  "messages": [],
  "nospace": "/",
  "usage": "",
  "values": [
    {
      "value": "https://github.com/rsteube/docker-mdbook",
      "display": "docker-mdbook",
      "description": "mdbook mermaid "
    },
    {
      "value": "https://github.com/rsteube/docker-mdbook-dtmo",
      "display": "docker-mdbook-dtmo",
      "description": "mdbook mdbook-mermaid mdbook-toc"
    },
    {
      "value": "https://github.com/rsteube/dotfiles",
      "display": "dotfiles",
      "style": "red"
    }
  ]
}

Note that for performance reasons only the first 100 search results are presented. Fast response times are important which limits what can be done in Carapace.