Skip to content

Commit

Permalink
figred out how to add an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dance2die committed Aug 7, 2020
1 parent 8ab9c5e commit 0a3f826
Showing 1 changed file with 12 additions and 54 deletions.
66 changes: 12 additions & 54 deletions src/App.tsx
@@ -1,88 +1,46 @@
import React from "react";

import input from "@replit/clui-input";
import createInput, { ICommand } from "@replit/clui-input";

const scripts = {
start: "run-p env:dev watch:css react-scripts:start",
build: "run-s env:prod build:css react-scripts:build",
test: "react-scripts test"
};

// console.info(`scripts`, Object.entries(scripts));

/**
* 1. build commands
* 2. show a full command in run
*/

const rootCommand = {
const rootCommand: ICommand = {
commands: {
...Object.keys(scripts).reduce((cmds, cmd) => {
cmds = {
...cmds,
[cmd]: {
run(args: any) {
console.info(`cmd(${cmd}) args =>`, args);
}, args: {
port: {
type: 'int',
}
}
}

},
};
return cmds;
}, {})
}
};

// console.info(`rootCommand2`, rootCommand2);
console.info(`rootCommand ==>`, rootCommand)

// const rootCommand = {
// commands: {
// open: {
// commands: {
// sesame: {
// run: (args) => {
// /* do something */
// console.info(`run args`, args);
// }
// }
// }
// }
// }
// };

const update = input({
const update = createInput({
command: rootCommand,
onUpdate: (updates) => {
console.info(`onUpdate updates`, updates);
if (updates.run) updates.run();
/* Update #1: `updates.options` will be
* [
* {
* "value": "open",
* "inputValue": "open",
* "searchValue": "o",
* "cursorTarget": 4
* }
* ]
*/
/* Update #2: `updates.options` will be
* [
* {
* "value": "sesame",
* "inputValue": "open sesame",
* "searchValue": "s",
* "cursorTarget": 12
* }
* ]
*/
if (updates.run) updates.run(9512);
}
});

// /* Update #1 */
// update({ value: "o", index: 1 });

// /* Update #2 */
// update({ value: "open s", index: 6 });

update({ value: "start", index: 6 });
update({ value: "start --port 1245" });
// update({ value: "build", index: 6, args: { port: "2222" } });
// update({ value: "test", index: 6, args: { port: "3333" } });

Expand Down

0 comments on commit 0a3f826

Please sign in to comment.