-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import type { CommandModule } from "yargs"; | ||
import type yargs from "yargs"; | ||
import { packCommand } from "./pack"; | ||
import { emitExperimentalWarning } from "../../utils/stability"; | ||
import { infoCommand } from "./info"; | ||
import { setStability } from "../stability"; | ||
|
||
const command = "plugin"; | ||
|
||
const describe = "[Experimental] Commands for kintone plugin"; | ||
const describe = "Commands for kintone plugin"; | ||
|
||
const builder = (args: yargs.Argv) => | ||
args.command(infoCommand).command(packCommand).demandCommand(); | ||
|
||
const handler = () => { | ||
emitExperimentalWarning("This feature is under early development"); | ||
/** noop **/ | ||
}; | ||
|
||
export const pluginCommand: CommandModule = { | ||
command, | ||
describe, | ||
builder, | ||
handler, | ||
}; | ||
export const pluginCommand: CommandModule = setStability( | ||
{ | ||
command, | ||
describe, | ||
builder, | ||
handler, | ||
}, | ||
"experimental", | ||
"This feature is under early development", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { ArgumentsCamelCase, CommandModule } from "yargs"; | ||
import { | ||
emitDeprecationWarning, | ||
emitExperimentalWarning, | ||
} from "../utils/stability"; | ||
|
||
/** | ||
* Set stability index to a command. | ||
* - Show stability on help message | ||
* - Emit warning on execution | ||
* @param cmd Command module | ||
* @param stability "experimental" or "deprecated" | ||
* @param message additional information | ||
*/ | ||
export const setStability = <T = {}, U = {}>( | ||
cmd: CommandModule<T, U>, | ||
stability: "experimental" | "deprecated", | ||
message: string, | ||
): CommandModule<T, U> => { | ||
const { describe, handler, ...restCmd } = cmd; | ||
const newDescribe = buildDescriptionWithStability( | ||
describe, | ||
message, | ||
stability, | ||
); | ||
|
||
const newHandler = async (args: ArgumentsCamelCase<U>) => { | ||
switch (stability) { | ||
case "experimental": | ||
emitExperimentalWarning(message); | ||
break; | ||
case "deprecated": | ||
emitDeprecationWarning(message); | ||
break; | ||
} | ||
await handler(args); | ||
}; | ||
|
||
return { | ||
...restCmd, | ||
describe: newDescribe, | ||
handler: newHandler, | ||
}; | ||
}; | ||
|
||
const buildDescriptionWithStability = ( | ||
description: string | false | undefined, | ||
message: string, | ||
stability: "experimental" | "deprecated", | ||
): string => { | ||
const labels = { | ||
experimental: "Experimental", | ||
deprecated: "Deprecated", | ||
}; | ||
const label = labels[stability]; | ||
const msgLines = message.split("\n"); | ||
|
||
let output = ""; | ||
if (description) { | ||
output += description + "\n\n"; | ||
} | ||
|
||
output += `[${label}: ${msgLines[0]}]`; | ||
if (msgLines.length > 1) { | ||
output += `${"\n" + msgLines.slice(1)}`; | ||
} | ||
|
||
return output; | ||
}; |