@cere/rob-cli
Version:
CLI tool for deploying and managing rafts and data sources
92 lines • 3.32 kB
JavaScript
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const yargs_1 = __importDefault(require("yargs/yargs"));
const helpers_1 = require("yargs/helpers");
const data_source_1 = require("./commands/data-source");
const raft_1 = require("./commands/raft");
const package_json_1 = require("../package.json");
const api_client_1 = require("./lib/api-client");
const dotenv_1 = __importDefault(require("dotenv"));
// Load environment variables from .env file if present
dotenv_1.default.config();
// Store handlers to avoid any possible conflicts
const dataSourceHandler = data_source_1.deployDataSourceCommand.handler;
const raftHandler = raft_1.deployRaftCommand.handler;
// Setup authentication middleware
const setupAuth = (argv) => {
// Initialize the API client with config and authentication
const basicAuth = argv.username && argv.password
? {
username: argv.username,
password: argv.password,
}
: undefined;
(0, api_client_1.configureApiClient)({
baseUrl: argv.baseUrl || 'https://rob.cere.io',
basicAuth,
});
return argv;
};
// Create CLI with proper nested command structure
const cli = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv));
cli
.scriptName('rob')
.usage('$0 <command> [options]')
.version(package_json_1.version)
.option('username', {
describe: 'Username for basic authentication',
type: 'string',
alias: 'u',
})
.option('password', {
describe: 'Password for basic authentication',
type: 'string',
alias: 'p',
})
.option('baseUrl', {
describe: 'API base URL',
type: 'string',
alias: 'b',
})
.command({
command: 'deploy',
describe: 'Deploy resources',
builder: (yargs) => {
return yargs
.command({
command: 'data-source <file>',
describe: 'Deploy data sources from a YAML file',
builder: data_source_1.deployDataSourceCommand.builder,
handler: (argv) => {
setupAuth(argv);
return dataSourceHandler(argv);
},
})
.command({
command: 'raft <file>',
describe: 'Deploy rafts from a YAML file',
builder: raft_1.deployRaftCommand.builder,
handler: (argv) => {
setupAuth(argv);
return raftHandler(argv);
},
})
.demandCommand(1, 'You need to specify what to deploy');
},
handler: () => { }, // Dummy handler for top-level command
})
.demandCommand(1, 'You need to specify a command.')
.strict()
.help()
.alias('h', 'help')
.alias('v', 'version')
.example('$0 deploy data-source /path/to/data-sources.yaml', 'Deploy data sources from YAML file')
.example('$0 deploy raft /path/to/rafts.yaml', 'Deploy rafts from YAML file')
.example('$0 deploy raft /path/to/rafts.yaml -u admin -p password', 'Deploy rafts with basic authentication')
.epilogue('For more information, check out the documentation at https://docs.cere.network')
.parse();
//# sourceMappingURL=index.js.map