Skip to content

Commit 6c89796

Browse files
committed
feat: add more CLI commands
1 parent 83fbec1 commit 6c89796

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

addons/browser/locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"New Page#!browser.1": "新页面",
3-
"Open Web Page#!browser.2": "打开网页"
3+
"Open Web Page#!browser.2": "打开网页",
4+
"Browse URL#!cli.description.browse": "访问 URL",
5+
"<url>#!cli.usage.browse": "<url>"
46
}

addons/browser/src/main/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import * as commas from 'commas:api/main'
22

33
export default () => {
44

5+
commas.context.provide('cli.command', {
6+
command: 'browse',
7+
description: 'Browse URL#!cli.description.browse',
8+
usage: '<url>#!cli.usage.browse',
9+
async handler({ sender, argv }) {
10+
commas.frame.send(sender, 'open-browser', argv[0])
11+
},
12+
})
13+
514
commas.i18n.addTranslationDirectory('locales')
615

716
commas.keybinding.addKeyBindingsFile('keybindings.json')

addons/cli/src/main/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface CommandModule {
1717
command: string,
1818
description?: string,
1919
usage?: string,
20-
handler: (context: CommandContext) => Generable<string, string | undefined, string | undefined>,
20+
handler: (context: CommandContext) => Generable<string, string | void, string | void>,
2121
}
2222

2323
function getCommandModule(command: string, commands: CommandModule[]) {
@@ -32,7 +32,7 @@ function getCommandModule(command: string, commands: CommandModule[]) {
3232
function executeCommand(
3333
inputContext: CommandContext,
3434
commands: CommandModule[],
35-
): AsyncGenerator<string, string | undefined, string | undefined> {
35+
): AsyncGenerator<string, string | void, string | void> {
3636
const [command, ...argv] = inputContext.argv
3737
const mod = getCommandModule(command, commands)
3838
if (!mod) {

addons/explorer/locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"Open Explorer#!explorer.1": "打开文件管理"
2+
"Open Explorer#!explorer.1": "打开文件管理",
3+
"List files in directory#!cli.description.list": "列出目录下的文件",
4+
"[directory]#!cli.usage.list": "[目录]"
35
}

addons/explorer/src/main/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ export default () => {
4949
}
5050
})
5151

52+
commas.context.provide('cli.command', {
53+
command: 'ls',
54+
description: 'List files in directory#!cli.description.list',
55+
usage: '[directory]#!cli.usage.list',
56+
async handler({ sender, argv, cwd }) {
57+
const directory = argv.length ? path.resolve(cwd, argv[0]) : cwd
58+
await fs.promises.access(directory, fs.constants.R_OK)
59+
commas.frame.send(sender, 'open-explorer', directory)
60+
},
61+
})
62+
5263
commas.i18n.addTranslationDirectory('locales')
5364

5465
commas.keybinding.addKeyBindingsFile('keybindings.json')

0 commit comments

Comments
 (0)