Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

carapace-scrape

The carapace-scrape skill creates a Spec by scraping the source code of a CLI tool.

Instructions

  1. start crush in an empty directory
  2. ctrl+p, TAB, then select the skill
  3. run with scrape https://github.com/some/repo

Result

# yaml-language-server: $schema=https://carapace.sh/schemas/command.json
name: pgxcli [DBNAME] [USERNAME]
description: Interactive PostgreSQL command-line client for querying and managing databases.
flags:
    --debug: Enable debug mode for verbose logging.
    -U, --user=: Username to connect to the postgres database.
    -W, --password: Force password prompt
    -d, --dbname=: database name to connect to.
    -h, --host=: host address of the postgres database
    -i, --interactive: Interactive connection mode
    -p, --port=: port number at which the postgres server is listening
    -u, --username=: Username to connect to the postgres database.
    -w, --no-password: never prompt for the password
persistentflags:
    --help&: Print usage
commands:
    - name: completion
      description: Generate the autocompletion script for the specified shell
      commands:
        - name: bash
          description: Generate the autocompletion script for bash
          flags:
            --no-descriptions: disable completion descriptions
        - name: fish
          description: Generate the autocompletion script for fish
          flags:
            --no-descriptions: disable completion descriptions
        - name: powershell
          description: Generate the autocompletion script for powershell
          flags:
            --no-descriptions: disable completion descriptions
        - name: zsh
          description: Generate the autocompletion script for zsh
          flags:
            --no-descriptions: disable completion descriptions
    - name: help [command]
      description: Help about any command

Intermediate build

FROM golang
ARG VERSION

WORKDIR /
RUN git clone https://github.com/balajz/pgxcli --branch "${VERSION}" --depth 1

ADD pgxcli.patch /

WORKDIR /pgxcli
RUN git apply ../pgxcli.patch
RUN go get github.com/carapace-sh/carapace
RUN GOBIN=/usr/bin/ go install ./cmd/pgxcli

ENTRYPOINT ["pgxcli", "_carapace", "spec"]
diff --git a/internal/cli/root.go b/internal/cli/root.go
index de82940..0efbec7 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -1,6 +1,7 @@
 package cli
 
 import (
+	"github.com/carapace-sh/carapace"
 	"context"
 	"fmt"
 	"os"
@@ -115,6 +116,7 @@ func NewRootCmd(ctx context.Context, cliCtx *CliContext) *cobra.Command {
 	interactiveConnFlag.bind(rootCmd)
 
 	rootCmd.MarkFlagsMutuallyExclusive("no-password", "password")
+	carapace.Gen(rootCmd)
 
 	return rootCmd
 }