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

     1  // Copyright 2017 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  
    10  	"go.fuchsia.dev/jiri"
    11  	"go.fuchsia.dev/jiri/cmdline"
    12  )
    13  
    14  // cmdSelfUpdate represents the "jiri update" command.
    15  var cmdSelfUpdate = &cmdline.Command{
    16  	Runner: cmdline.RunnerFunc(runSelfUpdate),
    17  	Name:   "selfupdate",
    18  	Short:  "Update jiri tool",
    19  	Long: `
    20  Updates jiri tool and replaces current one with the latest`,
    21  }
    22  
    23  func runSelfUpdate(env *cmdline.Env, args []string) error {
    24  	if len(args) > 0 {
    25  		return fmt.Errorf("unexpected number of arguments")
    26  	}
    27  
    28  	if err := jiri.Update(true); err != nil {
    29  		return fmt.Errorf("Update failed: %s", err)
    30  	}
    31  	fmt.Println("Tool updated.")
    32  	return nil
    33  }