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

     1  // Copyright (c) 2018-2019, 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  )
    12  
    13  type jsonList struct {
    14  	Instance string `json:"instance"`
    15  	Pid      int    `json:"pid"`
    16  	Image    string `json:"img"`
    17  }
    18  
    19  func init() {
    20  	InstanceListCmd.Flags().SetInterspersed(false)
    21  
    22  	// -u|--user
    23  	InstanceListCmd.Flags().StringVarP(&username, "user", "u", "", `If running as root, list instances from "<username>"`)
    24  	InstanceListCmd.Flags().SetAnnotation("user", "argtag", []string{"<username>"})
    25  	InstanceListCmd.Flags().SetAnnotation("user", "envkey", []string{"USER"})
    26  
    27  	// -j|--json
    28  	InstanceListCmd.Flags().BoolVarP(&jsonFormat, "json", "j", false, "Print structured json instead of list")
    29  	InstanceListCmd.Flags().SetAnnotation("json", "envkey", []string{"JSON"})
    30  }
    31  
    32  // InstanceListCmd singularity instance list
    33  var InstanceListCmd = &cobra.Command{
    34  	Args: cobra.RangeArgs(0, 1),
    35  	Run: func(cmd *cobra.Command, args []string) {
    36  		listInstance()
    37  	},
    38  	DisableFlagsInUseLine: true,
    39  
    40  	Use:     docs.InstanceListUse,
    41  	Short:   docs.InstanceListShort,
    42  	Long:    docs.InstanceListLong,
    43  	Example: docs.InstanceListExample,
    44  }