github.com/hungdoo/bot@v0.0.0-20240325145135-dd1f386f7b81/src/packages/cmdparser/cli.go (about)

     1  package cmdparser
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/urfave/cli"
     8  )
     9  
    10  var app *cli.App
    11  var buf *bytes.Buffer
    12  
    13  func GetParser() *cli.App {
    14  	if app != nil {
    15  		return app
    16  	}
    17  	app = cli.NewApp()
    18  	app.Name = "tele"
    19  	app.UsageText = "command [command options] [arguments...]"
    20  	app.Email = "hungddoo@lol.com"
    21  	buf = new(bytes.Buffer)
    22  	app.CommandNotFound = func(c *cli.Context, command string) {
    23  		fmt.Fprintln(c.App.Writer, command, " not found")
    24  	}
    25  	app.Writer = buf
    26  	return app
    27  }
    28  
    29  func GetOutput() string {
    30  	out := buf.String()
    31  	buf.Reset()
    32  	return out
    33  }