Skip to content

Commit

Permalink
Add back status to queue and time option
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrlambda committed Oct 17, 2023
1 parent e4d04d1 commit 3d47eeb
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 74 deletions.
47 changes: 46 additions & 1 deletion executors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.do_cron = exports.do_envvar = exports.do_key = exports.do_inspect = exports.do_build = exports.do_redeploy = exports.do_deploy = exports.generateNewKey = exports.useExistingKey = exports.do_register = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0;
exports.do_queue_time = exports.printTableHeader = exports.alignLeft = exports.alignRight = exports.do_cron = exports.do_envvar = exports.do_key = exports.do_inspect = exports.do_build = exports.do_redeploy = exports.do_deploy = exports.generateNewKey = exports.useExistingKey = exports.do_register = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0;
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const utils_1 = require("./utils");
Expand Down Expand Up @@ -396,3 +396,48 @@ function do_cron(org, name, overwrite, event, expr) {
});
}
exports.do_cron = do_cron;
function alignRight(str, width) {
return str.length > width
? str.substring(0, width - 3) + "..."
: str.padStart(width, " ");
}
exports.alignRight = alignRight;
function alignLeft(str, width) {
return str.length > width
? str.substring(0, width - 3) + "..."
: str.padEnd(width, " ");
}
exports.alignLeft = alignLeft;
function printTableHeader(prefix, widths) {
let header = prefix +
Object.keys(widths)
.map((k) => k.trim().padEnd(widths[k]))
.join(" │ ");
(0, utils_1.output2)(header);
let divider = prefix +
Object.keys(widths)
.map((k) => "─".repeat(widths[k]))
.join("─┼─");
(0, utils_1.output2)(divider);
}
exports.printTableHeader = printTableHeader;
function do_queue_time(org, time) {
return __awaiter(this, void 0, void 0, function* () {
try {
let resp = yield (0, utils_1.sshReq)(`queue`, `--org`, org, `--time`, "" + time);
let queue = JSON.parse(resp);
printTableHeader("", {
Id: 6,
River: 12,
Event: 12,
Status: 7,
"Queue time": 20,
});
queue.forEach((x) => (0, utils_1.output2)(`${x.id}${alignRight(x.r, 12)}${alignLeft(x.e, 12)}${alignLeft(x.s, 7)}${new Date(x.q).toLocaleString()}`));
}
catch (e) {
throw e;
}
});
}
exports.do_queue_time = do_queue_time;
60 changes: 60 additions & 0 deletions executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,63 @@ export async function do_cron(
throw e;
}
}

export function alignRight(str: string, width: number) {
return str.length > width
? str.substring(0, width - 3) + "..."
: str.padStart(width, " ");
}

export function alignLeft(str: string, width: number) {
return str.length > width
? str.substring(0, width - 3) + "..."
: str.padEnd(width, " ");
}

export function printTableHeader(
prefix: string,
widths: { [key: string]: number }
) {
let header =
prefix +
Object.keys(widths)
.map((k) => k.trim().padEnd(widths[k]))
.join(" │ ");
output2(header);
let divider =
prefix +
Object.keys(widths)
.map((k) => "─".repeat(widths[k]))
.join("─┼─");
output2(divider);
}

export async function do_queue_time(org: string, time: number) {
try {
let resp = await sshReq(`queue`, `--org`, org, `--time`, "" + time);
let queue: {
id: string;
q: string;
e: string;
r: string;
s: string;
}[] = JSON.parse(resp);
printTableHeader("", {
Id: 6,
River: 12,
Event: 12,
Status: 7,
"Queue time": 20,
});
queue.forEach((x) =>
output2(
`${x.id}${alignRight(x.r, 12)}${alignLeft(x.e, 12)}${alignLeft(
x.s,
7
)}${new Date(x.q).toLocaleString()}`
)
);
} catch (e) {
throw e;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@merrymake/cli",
"version": "1.4.0",
"version": "1.5.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function makeSelectionInternal(option, extra) {
function makeSelection(option) {
return makeSelectionInternal(option, () => {
output("\n");
output((command += " " + option.long));
output((command +=
" " + (option.long.includes(" ") ? `'${option.long}'` : option.long)));
output("\n");
});
}
Expand All @@ -96,7 +97,7 @@ function cleanup() {
output(exports.NORMAL_COLOR);
output(exports.SHOW_CURSOR);
}
function choice(options, invertedQuiet = true, def = 0) {
function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0) {
return new Promise((resolve) => {
let quick = {};
let str = [];
Expand All @@ -116,7 +117,7 @@ function choice(options, invertedQuiet = true, def = 0) {
const o = options[i];
if ((0, args_1.getArgs)()[0] === o.long || (0, args_1.getArgs)()[0] === `-${o.short}`) {
(0, args_1.getArgs)().splice(0, 1);
resolve(invertedQuiet ? makeSelectionQuietly(o) : makeSelection(o));
resolve(invertedQuiet.cmd ? makeSelection(o) : makeSelectionQuietly(o));
return;
}
if (o.short)
Expand Down Expand Up @@ -154,7 +155,7 @@ function choice(options, invertedQuiet = true, def = 0) {
// stdout.write("" + yOffset);
// moveCursor(-("" + yOffset).length, -options.length + pos);
if (k === exports.ENTER) {
resolve(invertedQuiet
resolve(invertedQuiet.select
? makeSelection(options[pos])
: makeSelectionQuietly(options[pos]));
return;
Expand Down Expand Up @@ -291,7 +292,7 @@ function shortText(prompt, description, defaultValue) {
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
}
else if (/^[A-Za-z0-9@_.-/:;#=&?]$/.test(k)) {
else if (/^[A-Za-z0-9@_, .-/:;#=&?]$/.test(k)) {
moveCursor(-beforeCursor.length, 0);
beforeCursor += k;
node_process_1.stdout.clearLine(1);
Expand Down
13 changes: 8 additions & 5 deletions prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ function makeSelectionInternal(option: Option, extra: () => void) {
function makeSelection(option: Option) {
return makeSelectionInternal(option, () => {
output("\n");
output((command += " " + option.long));
output(
(command +=
" " + (option.long.includes(" ") ? `'${option.long}'` : option.long))
);
output("\n");
});
}
Expand All @@ -116,7 +119,7 @@ export type Option = {

export function choice(
options: Option[],
invertedQuiet = true,
invertedQuiet = { cmd: false, select: true },
def: number = 0
) {
return new Promise<never>((resolve) => {
Expand All @@ -137,7 +140,7 @@ export function choice(
const o = options[i];
if (getArgs()[0] === o.long || getArgs()[0] === `-${o.short}`) {
getArgs().splice(0, 1);
resolve(invertedQuiet ? makeSelectionQuietly(o) : makeSelection(o));
resolve(invertedQuiet.cmd ? makeSelection(o) : makeSelectionQuietly(o));
return;
}
if (o.short) quick[o.short] = o;
Expand Down Expand Up @@ -180,7 +183,7 @@ export function choice(
// moveCursor(-("" + yOffset).length, -options.length + pos);
if (k === ENTER) {
resolve(
invertedQuiet
invertedQuiet.select
? makeSelection(options[pos])
: makeSelectionQuietly(options[pos])
);
Expand Down Expand Up @@ -310,7 +313,7 @@ export function shortText(
stdout.clearLine(1);
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
} else if (/^[A-Za-z0-9@_.-/:;#=&?]$/.test(k)) {
} else if (/^[A-Za-z0-9@_, .-/:;#=&?]$/.test(k)) {
moveCursor(-beforeCursor.length, 0);
beforeCursor += k;
stdout.clearLine(1);
Expand Down
Loading

0 comments on commit 3d47eeb

Please sign in to comment.