本文整理汇总了Golang中github.com/docker/docker/pkg/homedir.GetShortcutString函数的典型用法代码示例。如果您正苦于以下问题:Golang GetShortcutString函数的具体用法?Golang GetShortcutString怎么用?Golang GetShortcutString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetShortcutString函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: PrintDefaults
// PrintDefaults prints, to standard error unless configured
// otherwise, the default values of all defined flags in the set.
func (f *FlagSet) PrintDefaults() {
writer := tabwriter.NewWriter(f.Out(), 20, 1, 3, ' ', 0)
home := homedir.Get()
// Don't substitute when HOME is /
if runtime.GOOS != "windows" && home == "/" {
home = ""
}
f.VisitAll(func(flag *Flag) {
format := " -%s=%s"
names := []string{}
for _, name := range flag.Names {
if name[0] != '#' {
names = append(names, name)
}
}
if len(names) > 0 {
val := flag.DefValue
if home != "" && strings.HasPrefix(val, home) {
val = homedir.GetShortcutString() + val[len(home):]
}
fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)
for i, line := range strings.Split(flag.Usage, "\n") {
if i != 0 {
line = " " + line
}
fmt.Fprintln(writer, "\t", line)
}
}
})
writer.Flush()
}
开发者ID:yckrasnodar,项目名称:docker,代码行数:36,代码来源:flag.go
示例2: preload
// preload initializes any global options and configuration
// before the main or sub commands are run
func preload(c *cli.Context) (err error) {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
defaultGPGKey = c.GlobalString("keyid")
home := homedir.Get()
homeShort := homedir.GetShortcutString()
// set the filestore variable
filestore = strings.Replace(c.GlobalString("file"), homeShort, home, 1)
// set gpg path variables
gpgPath = strings.Replace(c.GlobalString("gpgpath"), homeShort, home, 1)
publicKeyring = filepath.Join(gpgPath, "pubring.gpg")
secretKeyring = filepath.Join(gpgPath, "secring.gpg")
// if they passed an arguement, run the prechecks
// TODO(jfrazelle): this will run even if the command they issue
// does not exist, which is kinda shitty
if len(c.Args()) > 0 {
preChecks()
}
// we need to read the secrets file for all commands
// might as well be dry about it
s, err = readSecretsFile(filestore)
if err != nil {
logrus.Fatal(err)
}
return nil
}
开发者ID:juliengk,项目名称:pony,代码行数:36,代码来源:main.go
示例3: PrintDefaults
// PrintDefaults prints, to standard error unless configured
// otherwise, the default values of all defined flags in the set.
func (fs *FlagSet) PrintDefaults() {
writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0)
home := homedir.Get()
// Don't substitute when HOME is /
if runtime.GOOS != "windows" && home == "/" {
home = ""
}
// Add a blank line between cmd description and list of options
if fs.FlagCount() > 0 {
fmt.Fprintln(writer, "")
}
fs.VisitAll(func(flag *Flag) {
names := []string{}
for _, name := range flag.Names {
if name[0] != '#' {
names = append(names, name)
}
}
if len(names) > 0 && len(flag.Usage) > 0 {
val := flag.DefValue
if home != "" && strings.HasPrefix(val, home) {
val = homedir.GetShortcutString() + val[len(home):]
}
if isZeroValue(val) {
format := " -%s"
fmt.Fprintf(writer, format, strings.Join(names, ", -"))
} else {
format := " -%s=%s"
fmt.Fprintf(writer, format, strings.Join(names, ", -"), val)
}
for i, line := range strings.Split(flag.Usage, "\n") {
if i != 0 {
line = " " + line
}
fmt.Fprintln(writer, "\t", line)
}
}
})
writer.Flush()
}
开发者ID:winsx,项目名称:libnetwork,代码行数:47,代码来源:flag.go
示例4: TestHelpTextVerify
func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
testRequires(c, DaemonIsLinux)
// Make sure main help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Test for HOME set to its default value and set to "/" on linux
// Yes on windows setting up an array and looping (right now) isn't
// necessary because we just have one value, but we'll need the
// array/loop on linux so we might as well set it up so that we can
// test any number of home dirs later on and all we need to do is
// modify the array - the rest of the testing infrastructure should work
homes := []string{homedir.Get()}
// Non-Windows machines need to test for this special case of $HOME
if runtime.GOOS != "windows" {
homes = append(homes, "/")
}
homeKey := homedir.Key()
baseEnvs := appendBaseEnv(true)
// Remove HOME env var from list so we can add a new value later.
for i, env := range baseEnvs {
if strings.HasPrefix(env, homeKey+"=") {
baseEnvs = append(baseEnvs[:i], baseEnvs[i+1:]...)
break
}
}
for _, home := range homes {
// Dup baseEnvs and add our new HOME value
newEnvs := make([]string, len(baseEnvs)+1)
copy(newEnvs, baseEnvs)
newEnvs[len(newEnvs)-1] = homeKey + "=" + home
scanForHome := runtime.GOOS != "windows" && home != "/"
// Check main help text to make sure its not over 80 chars
helpCmd := exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, _, err := runCommandWithOutput(helpCmd)
c.Assert(err, checker.IsNil, check.Commentf(out))
lines := strings.Split(out, "\n")
foundTooLongLine := false
for _, line := range lines {
if !foundTooLongLine && len(line) > 80 {
c.Logf("Line is too long:\n%s", line)
foundTooLongLine = true
}
// All lines should not end with a space
c.Assert(line, checker.Not(checker.HasSuffix), " ", check.Commentf("Line should not end with a space"))
if scanForHome && strings.Contains(line, `=`+home) {
c.Fatalf("Line should use '%q' instead of %q:\n%s", homedir.GetShortcutString(), home, line)
}
if runtime.GOOS != "windows" {
i := strings.Index(line, homedir.GetShortcutString())
if i >= 0 && i != len(line)-1 && line[i+1] != '/' {
c.Fatalf("Main help should not have used home shortcut:\n%s", line)
}
}
}
// Make sure each cmd's help text fits within 90 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Pull the list of commands from the "Commands:" section of docker help
helpCmd = exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, _, err = runCommandWithOutput(helpCmd)
c.Assert(err, checker.IsNil, check.Commentf(out))
i := strings.Index(out, "Commands:")
c.Assert(i, checker.GreaterOrEqualThan, 0, check.Commentf("Missing 'Commands:' in:\n%s", out))
cmds := []string{}
// Grab all chars starting at "Commands:"
helpOut := strings.Split(out[i:], "\n")
// First line is just "Commands:"
if isLocalDaemon {
// Replace first line with "daemon" command since it's not part of the list of commands.
helpOut[0] = " daemon"
} else {
// Skip first line
helpOut = helpOut[1:]
}
// Create the list of commands we want to test
cmdsToTest := []string{}
for _, cmd := range helpOut {
// Stop on blank line or non-idented line
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
break
}
// Grab just the first word of each line
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
cmds = append(cmds, cmd) // Saving count for later
cmdsToTest = append(cmdsToTest, cmd)
}
//.........这里部分代码省略.........
开发者ID:RAMESHBABUK,项目名称:docker,代码行数:101,代码来源:docker_cli_help_test.go
示例5: TestHelpTextVerify
func TestHelpTextVerify(t *testing.T) {
// Make sure main help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Test for HOME set to its default value and set to "/" on linux
// Yes on windows setting up an array and looping (right now) isn't
// necessary because we just have one value, but we'll need the
// array/loop on linux so we might as well set it up so that we can
// test any number of home dirs later on and all we need to do is
// modify the array - the rest of the testing infrastructure should work
homes := []string{homedir.Get()}
// Non-Windows machines need to test for this special case of $HOME
if runtime.GOOS != "windows" {
homes = append(homes, "/")
}
homeKey := homedir.Key()
baseEnvs := os.Environ()
// Remove HOME env var from list so we can add a new value later.
for i, env := range baseEnvs {
if strings.HasPrefix(env, homeKey+"=") {
baseEnvs = append(baseEnvs[:i], baseEnvs[i+1:]...)
break
}
}
for _, home := range homes {
// Dup baseEnvs and add our new HOME value
newEnvs := make([]string, len(baseEnvs)+1)
copy(newEnvs, baseEnvs)
newEnvs[len(newEnvs)-1] = homeKey + "=" + home
scanForHome := runtime.GOOS != "windows" && home != "/"
// Check main help text to make sure its not over 80 chars
helpCmd := exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, ec, err := runCommandWithOutput(helpCmd)
if err != nil || ec != 0 {
t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
}
lines := strings.Split(out, "\n")
for _, line := range lines {
if len(line) > 80 {
t.Fatalf("Line is too long(%d chars):\n%s", len(line), line)
}
// All lines should not end with a space
if strings.HasSuffix(line, " ") {
t.Fatalf("Line should not end with a space: %s", line)
}
if scanForHome && strings.Contains(line, `=`+home) {
t.Fatalf("Line should use '%q' instead of %q:\n%s", homedir.GetShortcutString(), home, line)
}
if runtime.GOOS != "windows" {
i := strings.Index(line, homedir.GetShortcutString())
if i >= 0 && i != len(line)-1 && line[i+1] != '/' {
t.Fatalf("Main help should not have used home shortcut:\n%s", line)
}
}
}
// Make sure each cmd's help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Pull the list of commands from the "Commands:" section of docker help
helpCmd = exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, ec, err = runCommandWithOutput(helpCmd)
if err != nil || ec != 0 {
t.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
}
i := strings.Index(out, "Commands:")
if i < 0 {
t.Fatalf("Missing 'Commands:' in:\n%s", out)
}
// Grab all chars starting at "Commands:"
// Skip first line, its "Commands:"
cmds := []string{}
for _, cmd := range strings.Split(out[i:], "\n")[1:] {
// Stop on blank line or non-idented line
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
break
}
// Grab just the first word of each line
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
cmds = append(cmds, cmd)
helpCmd := exec.Command(dockerBinary, cmd, "--help")
helpCmd.Env = newEnvs
out, ec, err := runCommandWithOutput(helpCmd)
if err != nil || ec != 0 {
t.Fatalf("Error on %q help: %s\nexit code:%d", cmd, out, ec)
}
lines := strings.Split(out, "\n")
for _, line := range lines {
if len(line) > 80 {
//.........这里部分代码省略.........
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:101,代码来源:docker_cli_help_test.go
示例6: TestHelpTextVerify
func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
testRequires(c, DaemonIsLinux)
// Make sure main help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Test for HOME set to its default value and set to "/" on linux
// Yes on windows setting up an array and looping (right now) isn't
// necessary because we just have one value, but we'll need the
// array/loop on linux so we might as well set it up so that we can
// test any number of home dirs later on and all we need to do is
// modify the array - the rest of the testing infrastructure should work
homes := []string{homedir.Get()}
// Non-Windows machines need to test for this special case of $HOME
if runtime.GOOS != "windows" {
homes = append(homes, "/")
}
homeKey := homedir.Key()
baseEnvs := os.Environ()
// Remove HOME env var from list so we can add a new value later.
for i, env := range baseEnvs {
if strings.HasPrefix(env, homeKey+"=") {
baseEnvs = append(baseEnvs[:i], baseEnvs[i+1:]...)
break
}
}
for _, home := range homes {
// Dup baseEnvs and add our new HOME value
newEnvs := make([]string, len(baseEnvs)+1)
copy(newEnvs, baseEnvs)
newEnvs[len(newEnvs)-1] = homeKey + "=" + home
scanForHome := runtime.GOOS != "windows" && home != "/"
// Check main help text to make sure its not over 80 chars
helpCmd := exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, _, err := runCommandWithOutput(helpCmd)
c.Assert(err, checker.IsNil, check.Commentf(out))
lines := strings.Split(out, "\n")
for _, line := range lines {
c.Assert(len(line), checker.LessOrEqualThan, 80, check.Commentf("Line is too long:\n%s", line))
// All lines should not end with a space
c.Assert(line, checker.Not(checker.HasSuffix), " ", check.Commentf("Line should not end with a space"))
if scanForHome && strings.Contains(line, `=`+home) {
c.Fatalf("Line should use '%q' instead of %q:\n%s", homedir.GetShortcutString(), home, line)
}
if runtime.GOOS != "windows" {
i := strings.Index(line, homedir.GetShortcutString())
if i >= 0 && i != len(line)-1 && line[i+1] != '/' {
c.Fatalf("Main help should not have used home shortcut:\n%s", line)
}
}
}
// Make sure each cmd's help text fits within 90 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Pull the list of commands from the "Commands:" section of docker help
helpCmd = exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, _, err = runCommandWithOutput(helpCmd)
c.Assert(err, checker.IsNil, check.Commentf(out))
i := strings.Index(out, "Commands:")
c.Assert(i, checker.GreaterOrEqualThan, 0, check.Commentf("Missing 'Commands:' in:\n%s", out))
cmds := []string{}
// Grab all chars starting at "Commands:"
helpOut := strings.Split(out[i:], "\n")
// First line is just "Commands:"
if isLocalDaemon {
// Replace first line with "daemon" command since it's not part of the list of commands.
helpOut[0] = " daemon"
} else {
// Skip first line
helpOut = helpOut[1:]
}
// Create the list of commands we want to test
cmdsToTest := []string{}
for _, cmd := range helpOut {
// Stop on blank line or non-idented line
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
break
}
// Grab just the first word of each line
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
cmds = append(cmds, cmd) // Saving count for later
cmdsToTest = append(cmdsToTest, cmd)
}
// Add some 'two word' commands - would be nice to automatically
// calculate this list - somehow
cmdsToTest = append(cmdsToTest, "volume create")
cmdsToTest = append(cmdsToTest, "volume inspect")
//.........这里部分代码省略.........
开发者ID:sergiobuj,项目名称:docker,代码行数:101,代码来源:docker_cli_help_test.go
示例7: main
func main() {
app := cli.NewApp()
app.Name = "pony"
app.Version = VERSION
app.Author = "@jfrazelle"
app.Email = "[email protected]"
app.Usage = "Local File-Based Password, API Key, Secret, Recovery Code Store Backed By GPG"
app.Before = preload
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "run in debug mode",
},
cli.StringFlag{
Name: "file, f",
Value: fmt.Sprintf("%s/%s", homedir.GetShortcutString(), defaultFilestore),
Usage: "file to use for saving encrypted secrets",
},
cli.StringFlag{
Name: "gpgpath",
Value: fmt.Sprintf("%s/%s", homedir.GetShortcutString(), defaultGPGPath),
Usage: "filepath used for gpg keys",
},
cli.StringFlag{
Name: "keyid",
Usage: "optionally set specific gpg keyid/fingerprint to use for encryption & decryption",
EnvVar: fmt.Sprintf("%s_KEYID", strings.ToUpper(app.Name)),
},
}
app.Commands = []cli.Command{
{
Name: "add",
Aliases: []string{"save"},
Usage: "Add a new secret",
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 2 {
logrus.Errorf("You need to pass a key and value to the command. ex: %s %s com.example.apikey EUSJCLLAWE", app.Name, c.Command.Name)
cli.ShowSubcommandHelp(c)
return
}
// add the key value pair to secrets
key, value := args[0], args[1]
s.setKeyValue(key, value, false)
fmt.Printf("Added %s %s to secrets", key, value)
},
},
{
Name: "delete",
Aliases: []string{"rm"},
Usage: "Delete a secret",
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 1 {
cli.ShowSubcommandHelp(c)
return
}
key := args[0]
if _, ok := s.Secrets[key]; !ok {
logrus.Fatalf("Secret for (%s) does not exist", key)
}
delete(s.Secrets, key)
if err := writeSecretsFile(filestore, s); err != nil {
logrus.Fatal(err)
}
fmt.Printf("Secret %q deleted successfully", key)
},
},
{
Name: "get",
Usage: "Get the value of a secret",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "copy, c",
Usage: "copy the secret to your clipboard",
},
},
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 1 {
cli.ShowSubcommandHelp(c)
return
}
// add the key value pair to secrets
key := args[0]
if _, ok := s.Secrets[key]; !ok {
logrus.Fatalf("Secret for (%s) does not exist", key)
}
fmt.Println(s.Secrets[key])
// copy to clipboard
if c.Bool("copy") {
//.........这里部分代码省略.........
开发者ID:juliengk,项目名称:pony,代码行数:101,代码来源:main.go
示例8: TestHelpTextVerify
func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// Make sure main help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Test for HOME set to its default value and set to "/" on linux
// Yes on windows setting up an array and looping (right now) isn't
// necessary because we just have one value, but we'll need the
// array/loop on linux so we might as well set it up so that we can
// test any number of home dirs later on and all we need to do is
// modify the array - the rest of the testing infrastructure should work
homes := []string{homedir.Get()}
// Non-Windows machines need to test for this special case of $HOME
if runtime.GOOS != "windows" {
homes = append(homes, "/")
}
homeKey := homedir.Key()
baseEnvs := os.Environ()
// Remove HOME env var from list so we can add a new value later.
for i, env := range baseEnvs {
if strings.HasPrefix(env, homeKey+"=") {
baseEnvs = append(baseEnvs[:i], baseEnvs[i+1:]...)
break
}
}
for _, home := range homes {
// Dup baseEnvs and add our new HOME value
newEnvs := make([]string, len(baseEnvs)+1)
copy(newEnvs, baseEnvs)
newEnvs[len(newEnvs)-1] = homeKey + "=" + home
scanForHome := runtime.GOOS != "windows" && home != "/"
// Check main help text to make sure its not over 80 chars
helpCmd := exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, ec, err := runCommandWithOutput(helpCmd)
if err != nil || ec != 0 {
c.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
}
lines := strings.Split(out, "\n")
for _, line := range lines {
if len(line) > 80 {
c.Fatalf("Line is too long(%d chars):\n%s", len(line), line)
}
// All lines should not end with a space
if strings.HasSuffix(line, " ") {
c.Fatalf("Line should not end with a space: %s", line)
}
if scanForHome && strings.Contains(line, `=`+home) {
c.Fatalf("Line should use '%q' instead of %q:\n%s", homedir.GetShortcutString(), home, line)
}
if runtime.GOOS != "windows" {
i := strings.Index(line, homedir.GetShortcutString())
if i >= 0 && i != len(line)-1 && line[i+1] != '/' {
c.Fatalf("Main help should not have used home shortcut:\n%s", line)
}
}
}
// Make sure each cmd's help text fits within 80 chars and that
// on non-windows system we use ~ when possible (to shorten things).
// Pull the list of commands from the "Commands:" section of docker help
helpCmd = exec.Command(dockerBinary, "help")
helpCmd.Env = newEnvs
out, ec, err = runCommandWithOutput(helpCmd)
if err != nil || ec != 0 {
c.Fatalf("docker help should have worked\nout:%s\nec:%d", out, ec)
}
i := strings.Index(out, "Commands:")
if i < 0 {
c.Fatalf("Missing 'Commands:' in:\n%s", out)
}
// Grab all chars starting at "Commands:"
// Skip first line, its "Commands:"
cmds := []string{}
for _, cmd := range strings.Split(out[i:], "\n")[1:] {
var stderr string
// Stop on blank line or non-idented line
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
break
}
// Grab just the first word of each line
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
cmds = append(cmds, cmd)
// Check the full usage text
helpCmd := exec.Command(dockerBinary, cmd, "--help")
helpCmd.Env = newEnvs
out, stderr, ec, err = runCommandWithStdoutStderr(helpCmd)
if len(stderr) != 0 {
c.Fatalf("Error on %q help. non-empty stderr:%q", cmd, stderr)
}
//.........这里部分代码省略.........
开发者ID:fwalker,项目名称:dashboard,代码行数:101,代码来源:docker_cli_help_test.go
注:本文中的github.com/docker/docker/pkg/homedir.GetShortcutString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论