Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Async flag options? #78

Open
Open

Description

@devshorts

Is it possible to hydrate a list of options in the flags from an async function? A good use case would be to dynamically detect the input options for an array.

Activity

  1. RasPhilCo commented on Nov 12, 2019

    @RasPhilCo
    Contributor

    Options is string[] type. Would need some reworking to accomplish. You could get "close" and enforce options with a custom flag parser.

  2. biesbjerg commented on Mar 28, 2020

    @biesbjerg

    I'm also looking for more flexibility in this area.

    Specifically I want installed plugins (using @oclif/plugin-plugins) to be able to register themselves using hooks (runHook). runHooks is async and also not possible to execute this.config.runHooks outside of the Command's instance context, as far as I can tell.

    Are there any way to currently do this?

    import { Command, flags } from '@oclif/command'
    
    import { compilerRegistry } from '../compiler-registry';
    
    export default class Extract extends Command {
    
    	static flags = {
    		compiler: flags.string({
    			char: 'c',
    			required: true,
    			description: 'Compiler to use for translations',
    			options: () => {
    				return compilerRegistry.getRegistered().map(compiler => compiler.shortName);
    			}
    		})
    	}
    
    	async init() {
    		await this.config.runHook('register-compilers', {
    			id: 'register-compilers',
    			registry: compilerRegistry
    		});
    	}
    }
  3. sisou commented on Aug 25, 2021

    @sisou

    In my case I would like to make a flag's default function async, e.g. return a Promise. Is that reasonable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions