github.com/dmmcquay/sia@v1.3.1-0.20180712220038-9f8d535311b9/cmd/siac/daemoncmd.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/NebulousLabs/Sia/build"
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  var (
    11  	stopCmd = &cobra.Command{
    12  		Use:   "stop",
    13  		Short: "Stop the Sia daemon",
    14  		Long:  "Stop the Sia daemon.",
    15  		Run:   wrap(stopcmd),
    16  	}
    17  
    18  	updateCheckCmd = &cobra.Command{
    19  		Use:   "check",
    20  		Short: "Check for available updates",
    21  		Long:  "Check for available updates.",
    22  		Run:   wrap(updatecheckcmd),
    23  	}
    24  
    25  	updateCmd = &cobra.Command{
    26  		Use:   "update",
    27  		Short: "Update Sia",
    28  		Long:  "Check for (and/or download) available updates for Sia.",
    29  		Run:   wrap(updatecmd),
    30  	}
    31  
    32  	versionCmd = &cobra.Command{
    33  		Use:   "version",
    34  		Short: "Print version information",
    35  		Long:  "Print version information.",
    36  		Run:   wrap(versioncmd),
    37  	}
    38  )
    39  
    40  // version prints the version of siac and siad.
    41  func versioncmd() {
    42  	fmt.Println("Sia Client")
    43  	fmt.Println("\tVersion " + build.Version)
    44  	if build.GitRevision != "" {
    45  		fmt.Println("\tGit Revision " + build.GitRevision)
    46  		fmt.Println("\tBuild Time   " + build.BuildTime)
    47  	}
    48  	dvg, err := httpClient.DaemonVersionGet()
    49  	if err != nil {
    50  		fmt.Println("Could not get daemon version:", err)
    51  		return
    52  	}
    53  	fmt.Println("Sia Daemon")
    54  	fmt.Println("\tVersion " + dvg.Version)
    55  	if build.GitRevision != "" {
    56  		fmt.Println("\tGit Revision " + dvg.GitRevision)
    57  		fmt.Println("\tBuild Time   " + dvg.BuildTime)
    58  	}
    59  }
    60  
    61  // stopcmd is the handler for the command `siac stop`.
    62  // Stops the daemon.
    63  func stopcmd() {
    64  	err := httpClient.DaemonStopGet()
    65  	if err != nil {
    66  		die("Could not stop daemon:", err)
    67  	}
    68  	fmt.Println("Sia daemon stopped.")
    69  }
    70  
    71  func updatecmd() {
    72  	update, err := httpClient.DaemonUpdateGet()
    73  	if err != nil {
    74  		fmt.Println("Could not check for update:", err)
    75  		return
    76  	}
    77  	if !update.Available {
    78  		fmt.Println("Already up to date.")
    79  		return
    80  	}
    81  
    82  	err = httpClient.DaemonUpdatePost()
    83  	if err != nil {
    84  		fmt.Println("Could not apply update:", err)
    85  		return
    86  	}
    87  	fmt.Printf("Updated to version %s! Restart siad now.\n", update.Version)
    88  }
    89  
    90  func updatecheckcmd() {
    91  	update, err := httpClient.DaemonUpdateGet()
    92  	if err != nil {
    93  		fmt.Println("Could not check for update:", err)
    94  		return
    95  	}
    96  	if update.Available {
    97  		fmt.Printf("A new release (v%s) is available! Run 'siac update' to install it.\n", update.Version)
    98  	} else {
    99  		fmt.Println("Up to date.")
   100  	}
   101  }