@pippit-dev/cli 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/checksums.txt +6 -6
- package/cmd/root.go +5 -0
- package/cmd/short_drama_test.go +49 -0
- package/internal/version/version.go +61 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ matching prebuilt binary for macOS, Linux, or Windows:
|
|
|
10
10
|
```bash
|
|
11
11
|
npx @pippit-dev/cli@latest install
|
|
12
12
|
export XYQ_ACCESS_KEY="<access-key>"
|
|
13
|
+
pippit-cli --version
|
|
13
14
|
pippit-cli short-drama +submit-run --message "写一个赛博朋克短剧开头"
|
|
14
15
|
pippit-cli short-drama +upload-file --path ./story.md
|
|
15
16
|
pippit-cli short-drama +get-thread --thread-id thread_123 --run-id run_456 --after-seq 0
|
|
@@ -23,6 +24,7 @@ Submit a Run task for the short drama scene:
|
|
|
23
24
|
|
|
24
25
|
```bash
|
|
25
26
|
export XYQ_ACCESS_KEY="<access-key>"
|
|
27
|
+
go run . --version
|
|
26
28
|
go run . short-drama +submit-run --message "写一个赛博朋克短剧开头"
|
|
27
29
|
go run . short-drama +upload-file --path ./story.md
|
|
28
30
|
go run . short-drama +get-thread --thread-id thread_123 --run-id run_456 --after-seq 0
|
package/checksums.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
ebff380937bb2269a116272d4bb0c5aaef0a176c2ffcfb6f337733411db34ddc pippit-cli-0.0.11-darwin-amd64.tar.gz
|
|
2
|
+
de27b844d0df2b112a2a78a24184d023cdf72b145d969497dd351924348161e4 pippit-cli-0.0.11-darwin-arm64.tar.gz
|
|
3
|
+
65da00716f772d3bbb823e10f36e87b73810c8d6f76d5f0c648274d43657f634 pippit-cli-0.0.11-linux-amd64.tar.gz
|
|
4
|
+
420dc63f6ea642c20b0a22f666c652d633d4ddad274b85096b51f74602e85a81 pippit-cli-0.0.11-linux-arm64.tar.gz
|
|
5
|
+
06350f1d74f4130bb420c237e5f804b4df1f358dfc195b659a70ddfd2d48832b pippit-cli-0.0.11-windows-amd64.zip
|
|
6
|
+
6919d1de3bec32499379bbcc820ccf3bafb3e843fdfa4cb9e826f90fae00feb2 pippit-cli-0.0.11-windows-arm64.zip
|
package/cmd/root.go
CHANGED
|
@@ -9,6 +9,7 @@ import (
|
|
|
9
9
|
updatecmd "github.com/Pippit-dev/pippit-cli/cmd/update"
|
|
10
10
|
"github.com/Pippit-dev/pippit-cli/internal/common"
|
|
11
11
|
"github.com/Pippit-dev/pippit-cli/internal/config"
|
|
12
|
+
"github.com/Pippit-dev/pippit-cli/internal/version"
|
|
12
13
|
"github.com/spf13/cobra"
|
|
13
14
|
)
|
|
14
15
|
|
|
@@ -28,9 +29,13 @@ func newRootCommand(stdout, stderr io.Writer, runner *common.Runner) *cobra.Comm
|
|
|
28
29
|
root := &cobra.Command{
|
|
29
30
|
Use: "pippit-cli",
|
|
30
31
|
Short: "Pippit CLI",
|
|
32
|
+
Long: "Pippit CLI submits short-drama workflows, downloads generated assets, and updates the installed CLI package.",
|
|
33
|
+
Version: version.Current(),
|
|
31
34
|
SilenceUsage: true,
|
|
32
35
|
SilenceErrors: true,
|
|
33
36
|
}
|
|
37
|
+
root.CompletionOptions.DisableDefaultCmd = true
|
|
38
|
+
root.SetVersionTemplate("{{.Version}}\n")
|
|
34
39
|
root.SetOut(stdout)
|
|
35
40
|
root.SetErr(stderr)
|
|
36
41
|
// root.AddCommand(authcmd.NewCommand(stdout, stderr, runner)) // temporarily disabled; auth is via access key injection
|
package/cmd/short_drama_test.go
CHANGED
|
@@ -12,6 +12,7 @@ import (
|
|
|
12
12
|
|
|
13
13
|
"github.com/Pippit-dev/pippit-cli/internal/common"
|
|
14
14
|
"github.com/Pippit-dev/pippit-cli/internal/config"
|
|
15
|
+
"github.com/Pippit-dev/pippit-cli/internal/version"
|
|
15
16
|
"github.com/bytedance/sonic"
|
|
16
17
|
"github.com/spf13/cobra"
|
|
17
18
|
)
|
|
@@ -90,6 +91,54 @@ func TestRootIncludesUpdateCommand(t *testing.T) {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
func TestRootDoesNotIncludeVersionCommand(t *testing.T) {
|
|
95
|
+
var stdout, stderr bytes.Buffer
|
|
96
|
+
root := NewRootCommand(&stdout, &stderr)
|
|
97
|
+
cmd, _, err := root.Find([]string{"version"})
|
|
98
|
+
if err == nil || cmd != root {
|
|
99
|
+
t.Fatalf("Find(version) = (%#v, %v), want unknown command", cmd, err)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func TestRootHelpListsSupportedCommands(t *testing.T) {
|
|
104
|
+
var stdout, stderr bytes.Buffer
|
|
105
|
+
root := NewRootCommand(&stdout, &stderr)
|
|
106
|
+
root.SetArgs([]string{"--help"})
|
|
107
|
+
|
|
108
|
+
if err := root.Execute(); err != nil {
|
|
109
|
+
t.Fatalf("Execute() error = %v, stderr = %s", err, stderr.String())
|
|
110
|
+
}
|
|
111
|
+
got := stdout.String()
|
|
112
|
+
for _, want := range []string{
|
|
113
|
+
"Pippit CLI submits short-drama workflows",
|
|
114
|
+
"short-drama",
|
|
115
|
+
"update",
|
|
116
|
+
"--version",
|
|
117
|
+
} {
|
|
118
|
+
if !strings.Contains(got, want) {
|
|
119
|
+
t.Fatalf("help output = %q, want %q", got, want)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for _, unwanted := range []string{"completion", "version "} {
|
|
123
|
+
if strings.Contains(got, unwanted) {
|
|
124
|
+
t.Fatalf("help output = %q, should not contain %q", got, unwanted)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func TestVersionFlagPrintsVersion(t *testing.T) {
|
|
130
|
+
var stdout, stderr bytes.Buffer
|
|
131
|
+
root := NewRootCommand(&stdout, &stderr)
|
|
132
|
+
root.SetArgs([]string{"--version"})
|
|
133
|
+
|
|
134
|
+
if err := root.Execute(); err != nil {
|
|
135
|
+
t.Fatalf("Execute() error = %v, stderr = %s", err, stderr.String())
|
|
136
|
+
}
|
|
137
|
+
if got := strings.TrimSpace(stdout.String()); got != version.Current() {
|
|
138
|
+
t.Fatalf("version flag output = %q, want %s", got, version.Current())
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
93
142
|
func TestShortDramaSubmitRunRequiresMessage(t *testing.T) {
|
|
94
143
|
var stdout, stderr bytes.Buffer
|
|
95
144
|
root := NewRootCommand(&stdout, &stderr)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package version
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"strings"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// Version is set by GoReleaser for release binaries.
|
|
11
|
+
var Version = "dev"
|
|
12
|
+
|
|
13
|
+
const packageName = "@pippit-dev/cli"
|
|
14
|
+
|
|
15
|
+
type packageJSON struct {
|
|
16
|
+
Name string `json:"name"`
|
|
17
|
+
Version string `json:"version"`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func Current() string {
|
|
21
|
+
if strings.TrimSpace(Version) != "" && Version != "dev" {
|
|
22
|
+
return strings.TrimSpace(Version)
|
|
23
|
+
}
|
|
24
|
+
if version := packageVersionFromWorktree(); version != "" {
|
|
25
|
+
return version
|
|
26
|
+
}
|
|
27
|
+
return Version
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func packageVersionFromWorktree() string {
|
|
31
|
+
dir, err := os.Getwd()
|
|
32
|
+
if err != nil {
|
|
33
|
+
return ""
|
|
34
|
+
}
|
|
35
|
+
for {
|
|
36
|
+
version := packageVersion(filepath.Join(dir, "package.json"))
|
|
37
|
+
if version != "" {
|
|
38
|
+
return version
|
|
39
|
+
}
|
|
40
|
+
parent := filepath.Dir(dir)
|
|
41
|
+
if parent == dir {
|
|
42
|
+
return ""
|
|
43
|
+
}
|
|
44
|
+
dir = parent
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func packageVersion(path string) string {
|
|
49
|
+
data, err := os.ReadFile(path)
|
|
50
|
+
if err != nil {
|
|
51
|
+
return ""
|
|
52
|
+
}
|
|
53
|
+
var pkg packageJSON
|
|
54
|
+
if err := json.Unmarshal(data, &pkg); err != nil {
|
|
55
|
+
return ""
|
|
56
|
+
}
|
|
57
|
+
if pkg.Name != packageName {
|
|
58
|
+
return ""
|
|
59
|
+
}
|
|
60
|
+
return strings.TrimSpace(pkg.Version)
|
|
61
|
+
}
|