forked from toolshed/abra
		
	feat: function to display help, error, & exit
This commit is contained in:
		@ -2,6 +2,7 @@ package cli
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"path"
 | 
			
		||||
	"sort"
 | 
			
		||||
@ -54,7 +55,7 @@ on your $PATH.
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		appType := c.Args().First()
 | 
			
		||||
		if appType == "" {
 | 
			
		||||
			cli.ShowSubcommandHelp(c)
 | 
			
		||||
			errorExit(c, "new", errors.New("no app type provided"))
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								cli/errors.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								cli/errors.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
package cli
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// errorExit exits the program on error, logs the error to the terminal, and shows the help command.
 | 
			
		||||
// When passing command, use an empty string to get the base command, and for a subcommand, give the name of the subcommand
 | 
			
		||||
// Example: "" for `app new` gets the app help, "new" gets the `new` subcommand help
 | 
			
		||||
func errorExit(c *cli.Context, command string, err interface{}) {
 | 
			
		||||
	cli.ShowCommandHelp(c, command)
 | 
			
		||||
	logrus.Error(err)
 | 
			
		||||
	os.Exit(1)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user