mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 09:57:20 +00:00
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.
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { hc } from 'hono/client'
|
|
import type { AppType } from '@shumai/api'
|
|
|
|
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
|
|
|
|
if (!apiServer) {
|
|
console.error('Error: SHUMAI_API_SERVER environment variable is not set.')
|
|
process.exit(1)
|
|
}
|
|
|
|
if (!apiKey) {
|
|
console.error(
|
|
'Error: SHUMAI_API_KEY environment variable is not set. Please generate a token in the Settings -> API Tokens tab.',
|
|
)
|
|
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}`,
|
|
},
|
|
})
|
|
}
|