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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright (c) 2019-2020, 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 (
"fmt"
"github.com/spf13/cobra"
"github.com/sylabs/singularity/v4/docs"
"github.com/sylabs/singularity/v4/internal/app/singularity"
"github.com/sylabs/singularity/v4/pkg/cmdline"
"github.com/sylabs/singularity/v4/pkg/sylog"
)
// -s|--set
var globalConfigSet bool
var globalConfigSetFlag = cmdline.Flag{
ID: "globalConfigSetFlag",
Value: &globalConfigSet,
DefaultValue: false,
Name: "set",
ShortHand: "s",
Usage: "set value of the configuration directive (for multi-value directives, it will add it)",
}
// -u|--unset
var globalConfigUnset bool
var globalConfigUnsetFlag = cmdline.Flag{
ID: "globalConfigUnsetFlag",
Value: &globalConfigUnset,
DefaultValue: false,
Name: "unset",
ShortHand: "u",
Usage: "unset value of the configuration directive (for multi-value directives, it will remove matching values)",
}
// -g|--get
var globalConfigGet bool
var globalConfigGetFlag = cmdline.Flag{
ID: "globalConfigGetFlag",
Value: &globalConfigGet,
DefaultValue: false,
Name: "get",
ShortHand: "g",
Usage: "get value of the configuration directive",
}
// -r|--reset
var globalConfigReset bool
var globalConfigResetFlag = cmdline.Flag{
ID: "globalConfigResetFlag",
Value: &globalConfigReset,
DefaultValue: false,
Name: "reset",
ShortHand: "r",
Usage: "reset the configuration directive value to its default value",
}
// -d|--dry-run
var globalConfigDryRun bool
var globalConfigDryRunFlag = cmdline.Flag{
ID: "globalConfigDryRunFlag",
Value: &globalConfigDryRun,
DefaultValue: false,
Name: "dry-run",
ShortHand: "d",
Usage: "dump resulting configuration on stdout but doesn't write it to singularity.conf",
}
// configGlobalCmd singularity config global
var configGlobalCmd = &cobra.Command{
Args: cobra.RangeArgs(1, 2),
DisableFlagsInUseLine: true,
PreRun: CheckRootOrUnpriv,
RunE: func(cmd *cobra.Command, args []string) error {
var op singularity.GlobalConfigOp
if globalConfigSet {
op = singularity.GlobalConfigSet
} else if globalConfigUnset {
op = singularity.GlobalConfigUnset
} else if globalConfigReset {
op = singularity.GlobalConfigReset
} else if globalConfigGet {
op = singularity.GlobalConfigGet
} else {
return fmt.Errorf("you must specify an option (eg: --set/--unset)")
}
if err := singularity.GlobalConfig(args, configurationFile, globalConfigDryRun, op); err != nil {
sylog.Fatalf("%s", err)
}
return nil
},
Use: docs.ConfigGlobalUse,
Short: docs.ConfigGlobalShort,
Long: docs.ConfigGlobalLong,
Example: docs.ConfigGlobalExample,
}
func init() {
addCmdInit(func(cmdManager *cmdline.CommandManager) {
cmdManager.RegisterFlagForCmd(&globalConfigSetFlag, configGlobalCmd)
cmdManager.RegisterFlagForCmd(&globalConfigUnsetFlag, configGlobalCmd)
cmdManager.RegisterFlagForCmd(&globalConfigGetFlag, configGlobalCmd)
cmdManager.RegisterFlagForCmd(&globalConfigResetFlag, configGlobalCmd)
cmdManager.RegisterFlagForCmd(&globalConfigDryRunFlag, configGlobalCmd)
})
}
|