github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/push.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package cli
     7  
     8  import (
     9  	"github.com/spf13/cobra"
    10  	"github.com/sylabs/singularity/docs"
    11  	"github.com/sylabs/singularity/internal/pkg/sylog"
    12  	client "github.com/sylabs/singularity/pkg/client/library"
    13  )
    14  
    15  var (
    16  	// PushLibraryURI holds the base URI to a Sylabs library API instance
    17  	PushLibraryURI string
    18  )
    19  
    20  func init() {
    21  	PushCmd.Flags().SetInterspersed(false)
    22  
    23  	PushCmd.Flags().StringVar(&PushLibraryURI, "library", "https://library.sylabs.io", "the library to push to")
    24  	PushCmd.Flags().SetAnnotation("library", "envkey", []string{"LIBRARY"})
    25  
    26  	SingularityCmd.AddCommand(PushCmd)
    27  }
    28  
    29  // PushCmd singularity push
    30  var PushCmd = &cobra.Command{
    31  	DisableFlagsInUseLine: true,
    32  	Args:                  cobra.ExactArgs(2),
    33  	PreRun:                sylabsToken,
    34  	Run: func(cmd *cobra.Command, args []string) {
    35  		// Push to library requires a valid authToken
    36  		if authToken != "" {
    37  			err := client.UploadImage(args[0], args[1], PushLibraryURI, authToken, "No Description")
    38  			if err != nil {
    39  				sylog.Fatalf("%v\n", err)
    40  			}
    41  		} else {
    42  			sylog.Fatalf("Couldn't push image to library: %v", authWarning)
    43  		}
    44  	},
    45  
    46  	Use:     docs.PushUse,
    47  	Short:   docs.PushShort,
    48  	Long:    docs.PushLong,
    49  	Example: docs.PushExample,
    50  }