github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/cmd/lhsm/main.go (about)

     1  // Copyright (c) 2018 DDN. 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  	"strings"
    11  
    12  	"github.com/intel-hpdd/logging/debug"
    13  
    14  	"gopkg.in/urfave/cli.v1"
    15  )
    16  
    17  var commands []cli.Command
    18  var version string // Set by build environment
    19  
    20  func main() {
    21  	app := cli.NewApp()
    22  	app.Usage = "HSM-related actions"
    23  	app.Commands = commands
    24  	app.Version = version
    25  	app.Authors = []cli.Author{
    26  		{
    27  			Name:  "IntelĀ® Enterprise Edition for Lustre* software Team",
    28  			Email: "HPDD-enterprise-lustre@intel.com",
    29  		},
    30  	}
    31  	app.Flags = []cli.Flag{
    32  		cli.BoolFlag{
    33  			Name:  "debug",
    34  			Usage: "Display debug logging to console",
    35  		},
    36  		cli.StringFlag{
    37  			Name:  "logfile, l",
    38  			Usage: "Log tool activity to this file",
    39  			Value: "",
    40  		},
    41  	}
    42  	app.Before = configureLogging
    43  	if err := app.Run(os.Args); err != nil {
    44  		fmt.Fprintf(os.Stderr, "%s\n", err)
    45  		os.Exit(1)
    46  	}
    47  }
    48  
    49  func configureLogging(c *cli.Context) error {
    50  	if c.Bool("debug") {
    51  		debug.Enable()
    52  	}
    53  
    54  	return nil
    55  }
    56  
    57  func logContext(c *cli.Context) {
    58  	for {
    59  		if c.Parent() == nil {
    60  			break
    61  		}
    62  		c = c.Parent()
    63  	}
    64  
    65  	debug.Printf("Context: %s", strings.Join(c.Args(), " "))
    66  }