bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/larksuite/cli/internal/qualitygate/manifest"
|
|
"github.com/larksuite/cli/internal/vfs"
|
|
)
|
|
|
|
func main() {
|
|
os.Exit(runManifestExport(os.Args[1:], os.Stderr))
|
|
}
|
|
|
|
func runManifestExport(args []string, stderr io.Writer) int {
|
|
configureManifestExportEnvironment()
|
|
|
|
fs := flag.NewFlagSet("manifest-export", flag.ContinueOnError)
|
|
fs.SetOutput(stderr)
|
|
var manifestOut string
|
|
var commandIndexOut string
|
|
fs.StringVar(&manifestOut, "manifest-out", "", "write hand-authored command manifest JSON to this path")
|
|
fs.StringVar(&commandIndexOut, "command-index-out", "", "write full command index JSON to this path")
|
|
if err := fs.Parse(args); err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: %v\n", err)
|
|
return 2
|
|
}
|
|
if manifestOut == "" || commandIndexOut == "" {
|
|
fmt.Fprintln(stderr, "manifest-export: --manifest-out and --command-index-out are required")
|
|
return 2
|
|
}
|
|
|
|
ctx := context.Background()
|
|
m, err := collectHandAuthored(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: collect command manifest: %v\n", err)
|
|
return 2
|
|
}
|
|
idx, err := collectCommandIndex(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: collect command index: %v\n", err)
|
|
return 2
|
|
}
|
|
if err := ensureParentDir(manifestOut); err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: create manifest output directory: %v\n", err)
|
|
return 2
|
|
}
|
|
if err := ensureParentDir(commandIndexOut); err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: create command index output directory: %v\n", err)
|
|
return 2
|
|
}
|
|
if err := manifest.WriteFile(manifestOut, manifest.KindCommandManifest, m); err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: write command manifest: %v\n", err)
|
|
return 2
|
|
}
|
|
if err := manifest.WriteFile(commandIndexOut, manifest.KindCommandIndex, idx); err != nil {
|
|
fmt.Fprintf(stderr, "manifest-export: write command index: %v\n", err)
|
|
return 2
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func ensureParentDir(path string) error {
|
|
dir := filepath.Dir(path)
|
|
if dir == "." || dir == "" {
|
|
return nil
|
|
}
|
|
return vfs.MkdirAll(dir, 0o755)
|
|
}
|
|
|
|
func configureManifestExportEnvironment() {
|
|
_ = os.Setenv("LARKSUITE_CLI_REMOTE_META", "off")
|
|
if os.Getenv("LARKSUITE_CLI_CONFIG_DIR") == "" {
|
|
_ = os.Setenv("LARKSUITE_CLI_CONFIG_DIR", filepath.Join(os.TempDir(), "quality-gate-cli-config"))
|
|
}
|
|
}
|