github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/cmd/bigslice/main.go (about)

     1  // Copyright 2019 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  	"flag"
     9  	"fmt"
    10  	"os"
    11  
    12  	"github.com/grailbio/base/log"
    13  	"github.com/grailbio/base/must"
    14  	"github.com/grailbio/bigslice/cmd/bigslice/bigslicecmd"
    15  )
    16  
    17  /*
    18  	bigslice run -local ...
    19  	bigslice run -cluster=ec2 github.com/grailbio/blah -args
    20  	bigslice run -cluster=ec2 -- -foo -bar
    21  	bigslice list // configured clusters, where they are coming from?
    22  */
    23  
    24  func usage() {
    25  	fmt.Fprintf(os.Stderr, `Bigslice is a tool for managing Bigslice builds and configuration.
    26  
    27  Usage:
    28  
    29  	bigslice <command> [arguments]
    30  
    31  The commands are:
    32  
    33  	setup-ec2   configure EC2 for use with Bigslice
    34  	build       build a bigslice program
    35  	run         run a bigslice program or source files
    36  `)
    37  	// TODO(marius): this command pulls in way too many global flags
    38  	// from other modules, including Vanadium; these dependencies
    39  	// should be pruned.
    40  	os.Exit(2)
    41  }
    42  
    43  func main() {
    44  	log.AddFlags()
    45  	log.SetFlags(0)
    46  	log.SetPrefix("bigslice: ")
    47  	must.Func = func(depth int, v ...interface{}) {
    48  		// Nothing to do if output fails.
    49  		_ = log.Output(depth+1, log.Error, fmt.Sprint(v...))
    50  		os.Exit(1)
    51  	}
    52  	flag.Usage = usage
    53  	flag.Parse()
    54  	if flag.NArg() == 0 {
    55  		flag.Usage()
    56  	}
    57  
    58  	if err := bigslicecmd.Init(); err != nil {
    59  		log.Fatal(err)
    60  	}
    61  
    62  	cmd, args := flag.Arg(0), flag.Args()[1:]
    63  	switch cmd {
    64  	default:
    65  		fmt.Fprintln(os.Stderr, "unknown command", cmd)
    66  		flag.Usage()
    67  	case "run":
    68  		runCmd(args)
    69  	case "build":
    70  		buildCmd(args)
    71  	case "setup-ec2":
    72  		setupEc2Cmd(args)
    73  	}
    74  }