go.fuchsia.dev/jiri@v0.0.0-20240502161911-b66513b29486/cmd/jiri/bootstrap.go (about)

     1  // Copyright 2018 The Fuchsia 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  	"fmt"
     9  	"strings"
    10  
    11  	"go.fuchsia.dev/jiri"
    12  	"go.fuchsia.dev/jiri/cipd"
    13  	"go.fuchsia.dev/jiri/cmdline"
    14  )
    15  
    16  var cmdBootstrap = &cmdline.Command{
    17  	Runner: cmdline.RunnerFunc(runBootstrap),
    18  	Name:   "bootstrap",
    19  	Short:  "Bootstrap essential packages",
    20  	Long: `
    21  Bootstrap essential packages such as cipd.
    22  `,
    23  	ArgsName: "<package ...>",
    24  	ArgsLong: "<package ...> is a list of packages that can be bootstrapped by jiri. If the list is empty, jiri will list supported packages.",
    25  }
    26  
    27  func runBootstrap(env *cmdline.Env, args []string) error {
    28  	if len(args) == 0 {
    29  		// Currently it only supports cipd. We may add more packages from buildtools in the future.
    30  		fmt.Printf("Supported package(s):\n\tcipd\n")
    31  		return nil
    32  	}
    33  	for _, v := range args {
    34  		switch strings.ToLower(v) {
    35  		case "cipd":
    36  			jirix, err := jiri.NewX(env)
    37  			if err != nil {
    38  				return err
    39  			}
    40  			cipdPath, err := cipd.Bootstrap(jirix, jirix.CIPDPath())
    41  			if err != nil {
    42  				return err
    43  			}
    44  			fmt.Printf("cipd bootstrapped to path:%q\n", cipdPath)
    45  
    46  		default:
    47  			return fmt.Errorf("unsupported package %q", v)
    48  		}
    49  	}
    50  	return nil
    51  }