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