github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/cli/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/wawandco/oxpecker/plugins"
     9  )
    10  
    11  var (
    12  	// The version of the CLI
    13  	version = "v1.5.3"
    14  )
    15  
    16  var (
    17  	// Version is a Command
    18  	_ plugins.Command = (*Command)(nil)
    19  )
    20  
    21  // Command command will print X version.
    22  type Command struct{}
    23  
    24  func (b Command) Name() string {
    25  	return "version"
    26  }
    27  
    28  func (c Command) Alias() string {
    29  	return "v"
    30  }
    31  
    32  func (b Command) ParentName() string {
    33  	return ""
    34  }
    35  
    36  func (b Command) HelpText() string {
    37  	return "returns the current version of Oxpecker CLI"
    38  }
    39  
    40  // Run prints the version of the Oxpecker cli
    41  func (b *Command) Run(ctx context.Context, root string, args []string) error {
    42  	fmt.Printf("Oxpecker version %v\n", version)
    43  
    44  	return nil
    45  }
    46  
    47  func (b *Command) FindRoot() string {
    48  	wd, err := os.Getwd()
    49  	if err != nil {
    50  		return ""
    51  	}
    52  
    53  	return wd
    54  }