Files
threshold/internal/cmd/common/help.go
T
Jim 591ec476e7 refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)
* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
2022-01-05 14:38:38 -05:00

142 lines
4.1 KiB
Go

package common
import (
"fmt"
"net/textproto"
"strings"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/mitchellh/go-wordwrap"
)
func SynopsisFunc(inFunc, resType string) string {
if inFunc == "" {
return wordwrap.WrapString(fmt.Sprintf("Manage Boundary %ss", resType), base.TermWidth)
}
articleType := resType
switch resType[0] {
case 'a', 'e', 'i', 'o':
articleType = fmt.Sprintf("an %s", articleType)
default:
articleType = fmt.Sprintf("a %s", articleType)
}
return wordwrap.WrapString(fmt.Sprintf("%s %s", textproto.CanonicalMIMEHeaderKey(inFunc), articleType), base.TermWidth)
}
func HelpMap(resType string) map[string]func() string {
prefixMap := map[string]string{
resource.Scope.String(): "o",
resource.AuthToken.String(): "at",
resource.AuthMethod.String(): "am",
resource.Account.String(): "a",
resource.Role.String(): "r",
resource.Group.String(): "g",
resource.User.String(): "u",
resource.HostCatalog.String(): "hc",
resource.HostSet.String(): "hs",
resource.Host.String(): "h",
resource.Session.String(): "s",
resource.Target.String(): "t",
}
return map[string]func() string{
"base": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s [sub command] [options] [args]",
"",
" This command allows operations on Boundary {{type}} resources. Example:",
"",
" Create {{articletype}}:",
"",
` $ boundary {{hyphentype}}s create -name prodops -description "For ProdOps usage"`,
"",
" Please see the {{hyphentype}}s subcommand help for detailed usage information.",
}, resType, prefixMap))
},
"create": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s create [options] [args]",
"",
" Create {{articletype}}. Example:",
"",
` $ boundary {{hyphentype}}s create -name prodops -description "{{uppertype}} for ProdOps"`,
"",
"",
}, resType, prefixMap))
},
"update": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s update [options] [args]",
"",
" Update {{articletype}} given its ID. Example:",
"",
` $ boundary {{hyphentype}}s update -id {{prefix}}_1234567890 -name "devops" -description "{{uppertype}} for DevOps"`,
"",
"",
}, resType, prefixMap))
},
"read": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s read [options] [args]",
"",
" Read {{articletype}} given its ID. Example:",
"",
` $ boundary {{hyphentype}}s read -id {{prefix}}_1234567890`,
"",
"",
}, resType, prefixMap))
},
"delete": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s delete [options] [args]",
"",
" Delete {{articletype}} given its ID. Example:",
"",
` $ boundary {{hyphentype}}s delete -id {{prefix}}_1234567890`,
"",
"",
}, resType, prefixMap))
},
"list": func() string {
return base.WrapForHelpText(subtype([]string{
"Usage: boundary {{hyphentype}}s list [options] [args]",
"",
" List {{type}}s within an enclosing scope or resource. Example:",
"",
` $ boundary {{hyphentype}}s list`,
"",
"",
}, resType, prefixMap))
},
}
}
func subtype(in []string, resType string, prefixMap map[string]string) []string {
hyphenType := strings.ReplaceAll(resType, " ", "-")
articleType := resType
switch resType[0] {
case 'a', 'e', 'i', 'o':
articleType = fmt.Sprintf("an %s", articleType)
default:
articleType = fmt.Sprintf("a %s", articleType)
}
for i, v := range in {
in[i] = strings.Replace(
strings.Replace(
strings.Replace(
strings.Replace(
strings.Replace(
v, "{{hyphentype}}", hyphenType, -1),
"{{type}}", resType, -1),
"{{uppertype}}", textproto.CanonicalMIMEHeaderKey(resType), -1),
"{{prefix}}", prefixMap[resType], -1),
"{{articletype}}", articleType, -1)
}
return in
}