用装饰器简化命令行工具开发

212 阅读1分钟
#!/usr/bin/env node
import { Cli, cli, Action, Option, Command, Param } from "imeepos/cli";

@Command("test", {
  desc: "",
  alias: "t1"
})
export class TestCommand {
  // test name -r true/false
  // test name --read=true/false
  @Option("r")
  read: boolean;
  
  @Param()
  nameItem: string;

  @Action()
  run() {
    console.log(this.nameItem);
    console.log(this.read);
  }
}

@Cli("1.0.0", {
  commands: [TestCommand]
})
export class TestCli {}

// 执行
cli(TestCli);