github.com/grailbio/base@v0.0.11/cmdutil/cmdline-test/cmdline-test.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/grailbio/base/cmdutil"
    11  	_ "github.com/grailbio/base/cmdutil/interactive"
    12  	"github.com/grailbio/base/vcontext"
    13  	"v.io/v23/context"
    14  	"v.io/x/lib/cmdline"
    15  	"v.io/x/lib/vlog"
    16  )
    17  
    18  var cmdRoot = &cmdline.Command{
    19  	Name: "cmdline-test",
    20  	Children: []*cmdline.Command{
    21  		logging,
    22  		access,
    23  	},
    24  }
    25  
    26  var logging = &cmdline.Command{
    27  	Name:     "logging",
    28  	ArgsName: "args",
    29  	Runner:   cmdutil.RunnerFunc(runner),
    30  }
    31  
    32  var access = &cmdline.Command{
    33  	Name:     "access",
    34  	ArgsName: "args",
    35  	Runner:   cmdutil.RunnerFuncWithAccessCheck(vcontext.Background, runnerWithRPC),
    36  }
    37  
    38  func main() {
    39  	cmdline.Main(cmdRoot)
    40  }
    41  
    42  func runner(_ *cmdline.Env, args []string) error {
    43  	fmt.Printf("%v\n", vlog.Log.LogDir())
    44  	vlog.Infof("-----")
    45  	for i, a := range args {
    46  		vlog.Infof("T: %d: %v", i, a)
    47  	}
    48  	return nil
    49  }
    50  
    51  func runnerWithRPC(ctx *context.T, _ *cmdline.Env, args []string) error {
    52  	fmt.Printf("%v\n", vlog.Log.LogDir())
    53  	vlog.Infof("-----")
    54  	for i, a := range args {
    55  		vlog.Infof("T: %d: %v", i, a)
    56  	}
    57  	return nil
    58  }