@saptools/cf-hana 0.2.0 → 0.2.1
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/dist/cli.js +27 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
+
import { formatCurrentCfAppSelector, readCurrentCfTarget } from "@saptools/cf-sync";
|
|
4
5
|
import { Command } from "commander";
|
|
5
6
|
|
|
6
7
|
// src/backup.ts
|
|
@@ -587,7 +588,7 @@ async function listColumns(connection, schema, table) {
|
|
|
587
588
|
|
|
588
589
|
// src/config.ts
|
|
589
590
|
var CLI_NAME = "cf-hana";
|
|
590
|
-
var CLI_VERSION = "0.2.
|
|
591
|
+
var CLI_VERSION = "0.2.1";
|
|
591
592
|
var ENV_PREFIX = "CF_HANA";
|
|
592
593
|
var DEFAULT_QUERY_TIMEOUT_MS = 3e4;
|
|
593
594
|
var DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
|
|
@@ -2544,6 +2545,25 @@ function parseQualifiedName(value) {
|
|
|
2544
2545
|
}
|
|
2545
2546
|
return { schema: value.slice(0, dot), table: value.slice(dot + 1) };
|
|
2546
2547
|
}
|
|
2548
|
+
async function resolveSelectorArgument(selector) {
|
|
2549
|
+
if (selector.includes("/")) {
|
|
2550
|
+
return selector;
|
|
2551
|
+
}
|
|
2552
|
+
const current = await readCurrentCfTarget().catch((error) => {
|
|
2553
|
+
throw new CfHanaError(
|
|
2554
|
+
"CONFIG",
|
|
2555
|
+
"No current CF target found. Run `cf target -o <org> -s <space>` or pass a full region/org/space/app selector.",
|
|
2556
|
+
{ cause: error }
|
|
2557
|
+
);
|
|
2558
|
+
});
|
|
2559
|
+
if (current === void 0) {
|
|
2560
|
+
throw new CfHanaError(
|
|
2561
|
+
"CONFIG",
|
|
2562
|
+
"No current CF target found. Run `cf target -o <org> -s <space>` or pass a full region/org/space/app selector."
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2565
|
+
return formatCurrentCfAppSelector(current, selector);
|
|
2566
|
+
}
|
|
2547
2567
|
function toConnectOptions(opts) {
|
|
2548
2568
|
assertPositiveOption("--limit", opts.limit);
|
|
2549
2569
|
assertPositiveOption("--timeout", opts.timeout);
|
|
@@ -2611,7 +2631,7 @@ async function runQuery(selector, sql, command) {
|
|
|
2611
2631
|
const opts = command.opts();
|
|
2612
2632
|
assertQueryOptions(sql, opts);
|
|
2613
2633
|
const cellLimit = resolveCellLimit(opts.cellLimit);
|
|
2614
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2634
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2615
2635
|
try {
|
|
2616
2636
|
const params = opts.param ?? [];
|
|
2617
2637
|
const backup = await client.backupWriteStatement(sql, params);
|
|
@@ -2652,7 +2672,7 @@ async function runQuery(selector, sql, command) {
|
|
|
2652
2672
|
}
|
|
2653
2673
|
async function runTables(selector, schema, command) {
|
|
2654
2674
|
const opts = command.opts();
|
|
2655
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2675
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2656
2676
|
try {
|
|
2657
2677
|
const tables = await client.listTables(schema ?? client.info.schema);
|
|
2658
2678
|
const rows = tables.map((table) => ({
|
|
@@ -2668,7 +2688,7 @@ async function runTables(selector, schema, command) {
|
|
|
2668
2688
|
async function runColumns(selector, target, command) {
|
|
2669
2689
|
const opts = command.opts();
|
|
2670
2690
|
const { schema, table } = parseQualifiedName(target);
|
|
2671
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2691
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2672
2692
|
try {
|
|
2673
2693
|
const columns = await client.listColumns(schema, table);
|
|
2674
2694
|
const rows = columns.map((column) => ({
|
|
@@ -2686,7 +2706,7 @@ async function runColumns(selector, target, command) {
|
|
|
2686
2706
|
async function runCount(selector, target, command) {
|
|
2687
2707
|
const opts = command.opts();
|
|
2688
2708
|
const { schema, table } = parseQualifiedName(target);
|
|
2689
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2709
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2690
2710
|
try {
|
|
2691
2711
|
const total = await client.count({ schema, table });
|
|
2692
2712
|
print2(String(total));
|
|
@@ -2696,7 +2716,7 @@ async function runCount(selector, target, command) {
|
|
|
2696
2716
|
}
|
|
2697
2717
|
async function runPing(selector, command) {
|
|
2698
2718
|
const opts = command.opts();
|
|
2699
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2719
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2700
2720
|
try {
|
|
2701
2721
|
const started = Date.now();
|
|
2702
2722
|
await client.query("SELECT 1 FROM DUMMY");
|
|
@@ -2709,7 +2729,7 @@ async function runPing(selector, command) {
|
|
|
2709
2729
|
}
|
|
2710
2730
|
async function runInfo(selector, command) {
|
|
2711
2731
|
const opts = command.opts();
|
|
2712
|
-
const client = await connect(selector, toConnectOptions(opts));
|
|
2732
|
+
const client = await connect(await resolveSelectorArgument(selector), toConnectOptions(opts));
|
|
2713
2733
|
try {
|
|
2714
2734
|
print2(formatInfo(client.info));
|
|
2715
2735
|
} finally {
|