mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 06:29:58 +00:00
feat(cli): generate shumai-cli commands from Operations with commander (#496)
Rebuild the CLI on commander. Commands for every cli-surface Operation (project ls, ls, mkdir, rename, move/mv, delete/rm) are generated from @shumai/operations: positionals, options, choices, numeric parsing and help text come from the Zod input schema. They call POST /api/ops/:name with x-shumai-client: cli. Existing invocations keep working. Adds --json, ls --type/--first/ --after, typo suggestions, and generated help. upload and create-version stay hand-written. Drops the unused @shumai/core dependency.
This commit is contained in:
+13
-1
@@ -1,7 +1,13 @@
|
||||
import { hc } from 'hono/client'
|
||||
import type { AppType } from '@shumai/api'
|
||||
|
||||
export function getClient() {
|
||||
export interface CliConfig {
|
||||
apiServer: string
|
||||
apiKey: string
|
||||
}
|
||||
|
||||
/** Reads the server URL and API token from the environment, exiting with guidance if missing. */
|
||||
export function getCliConfig(): CliConfig {
|
||||
const apiKey = process.env.SHUMAI_API_KEY
|
||||
const apiServer = process.env.SHUMAI_API_SERVER
|
||||
|
||||
@@ -17,6 +23,12 @@ export function getClient() {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
return { apiServer: apiServer.replace(/\/+$/, ''), apiKey }
|
||||
}
|
||||
|
||||
/** Typed REST client, used by commands that are not Operations yet (upload, create-version). */
|
||||
export function getClient() {
|
||||
const { apiServer, apiKey } = getCliConfig()
|
||||
return hc<AppType>(apiServer, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
|
||||
Reference in New Issue
Block a user