github.com/0xsequence/ethkit@v1.25.0/cmd/ethkit/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  var (
    11  	VERSION       = "dev"
    12  	GITBRANCH     = "branch"
    13  	GITCOMMIT     = "last commit"
    14  	GITCOMMITDATE = "last change"
    15  )
    16  
    17  var rootCmd = &cobra.Command{
    18  	Use:   "ethkit",
    19  	Short: "ethkit - Ethereum dev toolkit",
    20  	Long:  banner(),
    21  	Args:  cobra.MinimumNArgs(1),
    22  	CompletionOptions: cobra.CompletionOptions{
    23  		HiddenDefaultCmd: true,
    24  	},
    25  }
    26  
    27  func init() {
    28  	var versionCmd = &cobra.Command{
    29  		Use:   "version",
    30  		Short: "print the version number",
    31  		Run: func(cmd *cobra.Command, args []string) {
    32  			fmt.Println("ethkit", version())
    33  		},
    34  	}
    35  
    36  	rootCmd.AddCommand(versionCmd)
    37  }
    38  
    39  func main() {
    40  	if err := rootCmd.Execute(); err != nil {
    41  		fmt.Println(err)
    42  		os.Exit(1)
    43  	}
    44  }
    45  
    46  func help(cmd *cobra.Command) {
    47  	fmt.Printf("\n--\n\n")
    48  	cmd.Help()
    49  	os.Exit(0)
    50  }
    51  
    52  func version() string {
    53  	if GITBRANCH == "master" {
    54  		return fmt.Sprintf("%s (commit:%s %s)", VERSION, GITCOMMIT, GITCOMMITDATE)
    55  	}
    56  	return fmt.Sprintf("%s (commit:%s %s %s)", VERSION, GITCOMMIT, GITCOMMITDATE, GITBRANCH)
    57  }
    58  
    59  func banner() string {
    60  	s := ""
    61  	s += `=====================================================================================` + "\n"
    62  	s += `____________________________/\\\_____________________________________________________` + "\n"
    63  	s += `____________________________\/\\\___________/\\\_____________________________________` + "\n"
    64  	s += `__________________/\\\_______\/\\\__________\/\\\___________/\\\______/\\\___________` + "\n"
    65  	s += `____/\\\\\\\\___/\\\\\\\\\\\__\/\\\__________\/\\\___ /\\___\///____/\\\\\\\\\\\_____` + "\n"
    66  	s += `___/\\\         \////\\\////___\/\\\\\\\\\\___\/\\\_ /\\\___________\////\\\////_____` + "\n"
    67  	s += `___/\\\\\\\\\\\_____\/\\\_______\/\\\/////\\\__\/\\\\\\_______\/\\\_____\/\\\________` + "\n"
    68  	s += `___\//\\\            \/\\\_______\/\\\___\/\\\__\/\\\__\/\\\___\/\\\_____\/\\\_______` + "\n"
    69  	s += `____\//\\\\\\\\\\_____\//\\\\\____\/\\\___\/\\\__\/\\\__\/\\\___\/\\\_____\//\\\\\___` + "\n"
    70  	s += `_____\///////////______\//////_____\///____\///___\///___\///____\///______\/////____` + "\n"
    71  	s += "\n"
    72  	s += "==================================== we <3 Ethereum =================================\n"
    73  	return s
    74  }