Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrlambda committed Feb 23, 2024
1 parent ab1a42a commit 252246d
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
## Fixes and improvements
-

# 2.1.0
## Added features
- Add context sensitive `delete` command
## Fixes and improvements
- Trying to fix delete in text fields on Mac

# 2.0.0
## Breaking changes
- Make `event` use a multiselect, because it is much easier, safer, and faster to use, and can give a more helpful error message.
Expand Down
Binary file modified dist/windows.zip
Binary file not shown.
41 changes: 40 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_event = exports.do_spending = exports.do_remove_auto_approve = exports.do_auto_approve = exports.do_attach_role = exports.do_join = exports.do_post = exports.do_help = 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.addKnownHost = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0;
exports.do_delete_org = exports.do_delete_group = exports.do_delete_service = exports.do_event = exports.do_spending = exports.do_remove_auto_approve = exports.do_auto_approve = exports.do_attach_role = exports.do_join = exports.do_post = exports.do_help = 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.addKnownHost = 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 @@ -747,3 +747,42 @@ function do_event(key, events) {
});
}
exports.do_event = do_event;
function do_delete_service(org, group, service) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, utils_1.output2)(yield (0, utils_1.sshReq)(`service`, `--delete`, `--org`, org, `--team`, group, service));
if (fs_1.default.existsSync(service))
fs_1.default.renameSync(service, `(deleted) ${service}`);
}
catch (e) {
throw e;
}
});
}
exports.do_delete_service = do_delete_service;
function do_delete_group(org, group) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, utils_1.output2)(yield (0, utils_1.sshReq)(`team`, `--delete`, `--org`, org, group));
if (fs_1.default.existsSync(group))
fs_1.default.renameSync(group, `(deleted) ${group}`);
}
catch (e) {
throw e;
}
});
}
exports.do_delete_group = do_delete_group;
function do_delete_org(org) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, utils_1.output2)(yield (0, utils_1.sshReq)(`org`, `--delete`, org));
if (fs_1.default.existsSync(org))
fs_1.default.renameSync(org, `(deleted) ${org}`);
}
catch (e) {
throw e;
}
});
}
exports.do_delete_org = do_delete_org;
41 changes: 41 additions & 0 deletions executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,44 @@ export async function do_event(
throw e;
}
}

export async function do_delete_service(
org: string,
group: string,
service: string
) {
try {
output2(
await sshReq(
`service`,
`--delete`,
`--org`,
org,
`--team`,
group,
service
)
);
if (fs.existsSync(service)) fs.renameSync(service, `(deleted) ${service}`);
} catch (e) {
throw e;
}
}

export async function do_delete_group(org: string, group: string) {
try {
output2(await sshReq(`team`, `--delete`, `--org`, org, group));
if (fs.existsSync(group)) fs.renameSync(group, `(deleted) ${group}`);
} catch (e) {
throw e;
}
}

export async function do_delete_org(org: string) {
try {
output2(await sshReq(`org`, `--delete`, org));
if (fs.existsSync(org)) fs.renameSync(org, `(deleted) ${org}`);
} 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": "2.0.0",
"version": "2.1.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 15 additions & 9 deletions prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ function cleanup() {
output(exports.NORMAL_COLOR);
output(exports.SHOW_CURSOR);
}
function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0) {
function choice(options, opts) {
return new Promise((resolve) => {
var _a, _b;
let quick = {};
let str = [];
if (options.length === 1) {
if (options.length === 1 && (opts === null || opts === void 0 ? void 0 : opts.disableAutoPick) !== true) {
if ((0, args_1.getArgs)().length > 0)
(0, args_1.getArgs)().splice(0, 1);
resolve(invertedQuiet.cmd
resolve(((_a = opts === null || opts === void 0 ? void 0 : opts.invertedQuiet) === null || _a === void 0 ? void 0 : _a.cmd) === true
? makeSelection(options[0])
: makeSelectionQuietly(options[0]));
return;
Expand All @@ -130,7 +131,9 @@ function choice(options, invertedQuiet = { cmd: false, select: 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.cmd ? makeSelection(o) : makeSelectionQuietly(o));
resolve(((_b = opts === null || opts === void 0 ? void 0 : opts.invertedQuiet) === null || _b === void 0 ? void 0 : _b.cmd) === true
? makeSelection(o)
: makeSelectionQuietly(o));
return;
}
if (o.short)
Expand Down Expand Up @@ -162,21 +165,22 @@ function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0)
console.log("This console does not support TTY, please use the 'mmk'-command instead.");
process.exit(1);
}
let pos = def;
let pos = (opts === null || opts === void 0 ? void 0 : opts.def) || 0;
output(exports.YELLOW);
moveCursor(0, -options.length + pos);
output(`>`);
moveCursor(-1, 0);
// on any data into stdin
node_process_1.stdin.on("data", (listener = (key) => {
var _a;
let k = key.toString();
// moveCursor(0, options.length - pos);
// //let l = JSON.stringify(key);
// //output(l);
// stdout.write("" + yOffset);
// moveCursor(-("" + yOffset).length, -options.length + pos);
if (k === exports.ENTER) {
resolve(invertedQuiet.select
resolve(((_a = opts === null || opts === void 0 ? void 0 : opts.invertedQuiet) === null || _a === void 0 ? void 0 : _a.cmd) !== false
? makeSelection(options[pos])
: makeSelectionQuietly(options[pos]));
return;
Expand Down Expand Up @@ -453,15 +457,17 @@ function shortText(prompt, description, defaultValueArg) {
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
}
else if ((k === exports.DELETE || k.charCodeAt(0) === 127) &&
afterCursor.length > 0) {
else if (k === exports.DELETE && afterCursor.length > 0) {
moveCursor(-beforeCursor.length, 0);
afterCursor = afterCursor.substring(1);
node_process_1.stdout.clearLine(1);
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
}
else if ((k === exports.BACKSPACE || k.charCodeAt(0) === 8) &&
else if ((k === exports.BACKSPACE ||
k.charCodeAt(0) === 8 ||
k.charCodeAt(0) === 46 ||
k.charCodeAt(0) === 127) &&
beforeCursor.length > 0) {
moveCursor(-beforeCursor.length, 0);
beforeCursor = beforeCursor.substring(0, beforeCursor.length - 1);
Expand Down
31 changes: 19 additions & 12 deletions prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,19 @@ export type Option = {

export function choice(
options: Option[],
invertedQuiet = { cmd: false, select: true },
def: number = 0
opts?: {
def?: number;
disableAutoPick?: boolean;
invertedQuiet?: { cmd: boolean; select: boolean };
}
) {
return new Promise<never>((resolve) => {
let quick: { [key: string]: Option } = {};
let str: string[] = [];
if (options.length === 1) {
if (options.length === 1 && opts?.disableAutoPick !== true) {
if (getArgs().length > 0) getArgs().splice(0, 1);
resolve(
invertedQuiet.cmd
opts?.invertedQuiet?.cmd === true
? makeSelection(options[0])
: makeSelectionQuietly(options[0])
);
Expand All @@ -159,7 +162,11 @@ export function choice(
const o = options[i];
if (getArgs()[0] === o.long || getArgs()[0] === `-${o.short}`) {
getArgs().splice(0, 1);
resolve(invertedQuiet.cmd ? makeSelection(o) : makeSelectionQuietly(o));
resolve(
opts?.invertedQuiet?.cmd === true
? makeSelection(o)
: makeSelectionQuietly(o)
);
return;
}
if (o.short) quick[o.short] = o;
Expand Down Expand Up @@ -193,7 +200,7 @@ export function choice(
process.exit(1);
}

let pos = def;
let pos = opts?.def || 0;
output(YELLOW);
moveCursor(0, -options.length + pos);
output(`>`);
Expand All @@ -211,7 +218,7 @@ export function choice(
// moveCursor(-("" + yOffset).length, -options.length + pos);
if (k === ENTER) {
resolve(
invertedQuiet.select
opts?.invertedQuiet?.cmd !== false
? makeSelection(options[pos])
: makeSelectionQuietly(options[pos])
);
Expand Down Expand Up @@ -511,17 +518,17 @@ export function shortText(
stdout.clearLine(1);
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
} else if (
(k === DELETE || k.charCodeAt(0) === 127) &&
afterCursor.length > 0
) {
} else if (k === DELETE && afterCursor.length > 0) {
moveCursor(-beforeCursor.length, 0);
afterCursor = afterCursor.substring(1);
stdout.clearLine(1);
output(beforeCursor + afterCursor);
moveCursor(-afterCursor.length, 0);
} else if (
(k === BACKSPACE || k.charCodeAt(0) === 8) &&
(k === BACKSPACE ||
k.charCodeAt(0) === 8 ||
k.charCodeAt(0) === 46 ||
k.charCodeAt(0) === 127) &&
beforeCursor.length > 0
) {
moveCursor(-beforeCursor.length, 0);
Expand Down
Loading

0 comments on commit 252246d

Please sign in to comment.