github.com/kilpkonn/gtm-enhanced@v1.3.5/main.go (about)

     1  // Copyright 2016 Michael Schenk. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  
    11  	"github.com/git-time-metric/gtm/command"
    12  	"github.com/git-time-metric/gtm/util"
    13  	"github.com/mitchellh/cli"
    14  )
    15  
    16  // Version is the released version set during the release build process
    17  var Version = "0.0.0"
    18  
    19  func main() {
    20  	profileFunc := util.Profile(fmt.Sprintf("%+v", os.Args))
    21  	util.Debug.Printf("%+v", os.Args)
    22  	ui := &cli.ColoredUi{ErrorColor: cli.UiColorRed, Ui: &cli.BasicUi{Writer: os.Stdout, Reader: os.Stdin}}
    23  	c := cli.NewCLI("gtm", Version)
    24  	c.Args = os.Args[1:]
    25  	c.Commands = map[string]cli.CommandFactory{
    26  		"init": func() (cli.Command, error) {
    27  			return &command.InitCmd{
    28  				UI: ui,
    29  			}, nil
    30  		},
    31  		"record": func() (cli.Command, error) {
    32  			return &command.RecordCmd{
    33  				UI: ui,
    34  			}, nil
    35  		},
    36  		"commit": func() (cli.Command, error) {
    37  			return &command.CommitCmd{
    38  				UI: ui,
    39  			}, nil
    40  		},
    41  		"report": func() (cli.Command, error) {
    42  			return &command.ReportCmd{
    43  				UI: ui,
    44  			}, nil
    45  		},
    46  		"status": func() (cli.Command, error) {
    47  			return &command.StatusCmd{
    48  				UI: ui,
    49  			}, nil
    50  		},
    51  		"verify": func() (cli.Command, error) {
    52  			return &command.VerifyCmd{
    53  				UI:      ui,
    54  				Version: Version,
    55  			}, nil
    56  		},
    57  		"uninit": func() (cli.Command, error) {
    58  			return &command.UninitCmd{
    59  				UI: ui,
    60  			}, nil
    61  		},
    62  		"clean": func() (cli.Command, error) {
    63  			return &command.CleanCmd{
    64  				UI: ui,
    65  			}, nil
    66  		},
    67  	}
    68  
    69  	exitStatus, err := c.Run()
    70  	profileFunc()
    71  	if err != nil {
    72  		ui.Error(err.Error())
    73  	}
    74  
    75  	util.Debug.Print("exitStatus:", exitStatus)
    76  	os.Exit(exitStatus)
    77  }