gopkg.in/hugelgupf/u-root.v2@v2.0.0-20180831055005-3f8fdb0ce09d/pkg/bb/cmd/main.go (about)

     1  // Copyright 2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"log"
     9  	"os"
    10  	"path/filepath"
    11  
    12  	"github.com/u-root/u-root/pkg/bb"
    13  )
    14  
    15  func run() {
    16  	name := filepath.Base(os.Args[0])
    17  	if err := bb.Run(name); err != nil {
    18  		log.Fatalf("%s: %v", name, err)
    19  	}
    20  }
    21  
    22  func main() {
    23  	run()
    24  }
    25  
    26  func init() {
    27  	m := func() {
    28  		if len(os.Args) <= 1 {
    29  			log.Fatalf("You need to specify which command to invoke.")
    30  		}
    31  		// Use argv[1] as the name.
    32  		os.Args = os.Args[1:]
    33  		run()
    34  	}
    35  	bb.Register("bb", bb.Noop, m)
    36  	bb.RegisterDefault(bb.Noop, m)
    37  }