cli/directives/UsageDirective.js

/**
 * @module flitter-cli/directives/UsageDirective
 */

const Directive = require('../Directive')

/**
 * Directive to display help and usage information
 * 
 * @extends module:flitter-cli/Directive~Directive
 */
class UsageDirective extends Directive {

    /**
     * Get the name of the directive. Used by ./flitter.
     * @returns {string} "help"
     */
    static name(){
        return "help"
    }

    /**
     * Get the usage information for the directive. Used by ./flitter help.
     * @returns {string}
     */
    static help(){
        return "print usage information"
    }

    /**
     * Handle an invocation of the Directive. Prints the usage information for all registered instances of {@link module:flitter-cli/Directive~Directive}.
     * @param {module:libflitter/app/FlitterApp~FlitterApp} app - the Flitter app
     * @param {Array} argv - the CLI arguments passed to the directive
     * @returns {Promise<void>}
     */
    async handle(app, argv){
        console.log(`
___________________________             
___  __/__  /__(_)_  /__  /_____________
__  /_ __  /__  /_  __/  __/  _ \\_  ___/
_  __/ _  / _  / / /_ / /_ /  __/  /    
/_/    /_/  /_/  \\__/ \\__/ \\___//_/     
                                        
Welcome to Flitter! Specify a directive to get started:

USAGE: ./flitter <directive> [options]
`)
        
        for ( let name in this.cli.usage ){
            if ( !this.cli.usage.hasOwnProperty(name) ) continue
            console.log("\t"+name+"\t\t:\t"+this.cli.usage[name])
        }
        
        console.log(`
-----------------------------
powered by Flitter, © 2019 Garrett Mills
https://git.glmdev.tech/flitter
`)
    }
    
}

module.exports = exports = UsageDirective