Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sub-options to command info object provided by RegisterProv… #39

Merged
merged 5 commits into from
Feb 5, 2022

Conversation

LucasIcarus
Copy link

@LucasIcarus LucasIcarus commented Jun 1, 2021

PR Checklist

  • Fix lint errors
  • All tests passed
  • rebase commits

Change information

Extract subOptions metadata when RegisterProvider as Command Class constructor params.

support help like this

@Option({
  name: 'help',
  alias: 'h',
  description: 'help',
})
export class Help {
  constructor(regs: RegisterProvider) {
    console.log(pkg.name.toUpperCase())
    console.log('')

    regs.commands.forEach(data => {
      console.log(`  ${data.name} \<command\>${this.showDesc(data.description)}`)
      data.subOptions.forEach(sub => {
        console.log(`    ${sub.name} \<sub-option\>${this.showDesc(sub.description)}`)
      })
    })

    console.log('')

    regs.options.forEach(data => {
      const alias = data.alias ? ` -${data.alias}` : ''
      console.log(`  --${data.name}${alias} \<option\>${this.showDesc(data.description)}`)
    })

    console.log('')
  }

  private showDesc(desc: string): string {
    return desc ? ` --  ${desc}` : ''
  }
}

emit help info like this

  dev <command> --  启动主流程
    --config -c <sub-option> --  指定配置文件的路径
    --specific -s <sub-option> -- 指定某个具体入口
  clean <command> --  清除缓存

  --help -h <option> --  帮助信息
  --version -v <option> --  当前 cli 版本号

@LucasIcarus
Copy link
Author

下班回家临时写的..

commandsToDatas 这个函数的引用我大概检查了一下好像只有 factory 那里用到了. 没仔细看.

@LucasIcarus LucasIcarus force-pushed the feat/register_add_sub_options branch from 26c18c7 to 68c2910 Compare June 2, 2021 02:43
@@ -23,11 +23,15 @@ export interface CommandParams {
description?: string
}

export type OptionType = BooleanConstructor | StringConstructor | NumberConstructor | ArrayConstructor
export type OptionType = BooleanConstructor | StringConstructor | NumberConstructor | ArrayConstructor | [StringConstructor]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg 这个包允许的 OptionType 其实没有 ArrayConstructor.

如果要传数组需要通过 [String] 这种形式声明类型

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LucasIcarus
Copy link
Author

@unix 维特聚聚贴贴..

有空看下哈

@unix
Copy link
Owner

unix commented Jun 3, 2021

能提一个 Issue 聊一下 Feature 的具体变化、原因和使用场景吗

@LucasIcarus
Copy link
Author

LucasIcarus commented Jun 3, 2021

能提一个 Issue 聊一下 Feature 的具体变化、原因和使用场景吗

@unix 维特橘我提了 #40

@unix unix merged commit f732311 into unix:master Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants