forked from z2_cc/gitlink-cli
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package interactive
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/gitlink-org/gitlink-cli/cmd/cmdutil"
|
|
"github.com/gitlink-org/gitlink-cli/internal/context"
|
|
)
|
|
|
|
// NewInteractiveCmd creates the Cobra command for the interactive REPL.
|
|
func NewInteractiveCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "interactive",
|
|
Short: "Start interactive REPL with command palette",
|
|
Long: `Start an interactive REPL session with a command palette.
|
|
|
|
Type / to open the command palette with fuzzy search.
|
|
Use arrow keys to navigate, Enter to select, Tab to fill parameters.
|
|
Type "exit" or press Ctrl+D to quit.`,
|
|
Aliases: []string{"i"},
|
|
Example: ` gitlink interactive
|
|
gitlink i`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
// 交互模式默认用表格输出,更易阅读;用户显式指定 --format 时优先采用用户的值。
|
|
if cmdutil.Format == "" {
|
|
cmdutil.Format = "table"
|
|
}
|
|
owner, repo, err := context.ResolveOwnerRepo(cmdutil.Owner, cmdutil.Repo)
|
|
if err != nil {
|
|
owner = cmdutil.Owner
|
|
repo = cmdutil.Repo
|
|
}
|
|
return Run(owner, repo)
|
|
},
|
|
}
|
|
}
|