gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/bb/bbmain/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 is the busybox main.go template. 6 package main 7 8 import ( 9 "log" 10 "os" 11 "path/filepath" 12 13 "github.com/u-root/u-root/pkg/bb/bbmain" 14 "github.com/u-root/u-root/pkg/upath" 15 ) 16 17 func run() { 18 name := filepath.Base(os.Args[0]) 19 if err := bbmain.Run(name); err != nil { 20 log.Fatalf("%s: %v", name, err) 21 } 22 } 23 24 func main() { 25 os.Args[0] = upath.ResolveUntilLastSymlink(os.Args[0]) 26 27 run() 28 } 29 30 func init() { 31 m := func() { 32 if len(os.Args) == 1 { 33 log.Fatalf("Invalid busybox command: %q", os.Args) 34 } 35 // Use argv[1] as the name. 36 os.Args = os.Args[1:] 37 run() 38 } 39 bbmain.Register("bb", bbmain.Noop, bbmain.ListCmds) 40 bbmain.RegisterDefault(bbmain.Noop, m) 41 }