github.com/DEVELOPEST/gtm-core@v1.0.3/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/DEVELOPEST/gtm-core/command"
    12  	"github.com/DEVELOPEST/gtm-core/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{
    23  		ErrorColor: cli.UiColorRed,
    24  		WarnColor:  cli.UiColorYellow,
    25  		InfoColor:  cli.UiColorCyan,
    26  		Ui:         &cli.BasicUi{Writer: os.Stdout, Reader: os.Stdin},
    27  	}
    28  	c := cli.NewCLI("gtm", Version)
    29  	c.Args = os.Args[1:]
    30  	c.HelpWriter = os.Stdout
    31  	c.ErrorWriter = os.Stderr
    32  	c.Commands = map[string]cli.CommandFactory{
    33  		"init": func() (cli.Command, error) {
    34  			return &command.InitCmd{
    35  				UI: ui,
    36  			}, nil
    37  		},
    38  		"record": func() (cli.Command, error) {
    39  			return &command.RecordCmd{
    40  				UI: ui,
    41  			}, nil
    42  		},
    43  		"commit": func() (cli.Command, error) {
    44  			return &command.CommitCmd{
    45  				UI: ui,
    46  			}, nil
    47  		},
    48  		"report": func() (cli.Command, error) {
    49  			return &command.ReportCmd{
    50  				UI: ui,
    51  			}, nil
    52  		},
    53  		"status": func() (cli.Command, error) {
    54  			return &command.StatusCmd{
    55  				UI: ui,
    56  			}, nil
    57  		},
    58  		"verify": func() (cli.Command, error) {
    59  			return &command.VerifyCmd{
    60  				UI:      ui,
    61  				Version: Version,
    62  			}, nil
    63  		},
    64  		"uninit": func() (cli.Command, error) {
    65  			return &command.UninitCmd{
    66  				UI: ui,
    67  			}, nil
    68  		},
    69  		"clean": func() (cli.Command, error) {
    70  			return &command.CleanCmd{
    71  				UI: ui,
    72  			}, nil
    73  		},
    74  		"rewrite": func() (cli.Command, error) {
    75  			return &command.RewriteCmd{
    76  				UI: ui,
    77  			}, nil
    78  		},
    79  	}
    80  
    81  	exitStatus, err := c.Run()
    82  	profileFunc()
    83  	if err != nil {
    84  		ui.Error(err.Error())
    85  	}
    86  
    87  	util.Debug.Print("exitStatus:", exitStatus)
    88  	os.Exit(exitStatus)
    89  }