本文整理汇总了Golang中github.com/urfave/cli.NewExitError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewExitError函数的具体用法?Golang NewExitError怎么用?Golang NewExitError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewExitError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: execApplyCommand
// Executes the "apply" command
func execApplyCommand(c *cli.Context) error {
if len(c.Args()) < 1 {
return cli.NewExitError(errNoModuleName.Error(), 64)
}
L := lua.NewState()
defer L.Close()
config := &catalog.Config{
Module: c.Args()[0],
DryRun: c.Bool("dry-run"),
Logger: resource.DefaultLogger,
SiteRepo: c.String("siterepo"),
L: L,
}
katalog := catalog.New(config)
if err := katalog.Load(); err != nil {
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
}
if err := katalog.Run(); err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
示例2: ProjectDelete
// ProjectDelete deletes services.
func ProjectDelete(p project.APIProject, c *cli.Context) error {
options := options.Delete{
RemoveVolume: c.Bool("v"),
}
if !c.Bool("force") {
stoppedContainers, err := p.Containers(context.Background(), project.Filter{
State: project.Stopped,
}, c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
if len(stoppedContainers) == 0 {
fmt.Println("No stopped containers")
return nil
}
fmt.Printf("Going to remove %v\nAre you sure? [yN]\n", strings.Join(stoppedContainers, ", "))
var answer string
_, err = fmt.Scanln(&answer)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
if answer != "y" && answer != "Y" {
return nil
}
}
err := p.Delete(context.Background(), options, c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
示例3: statusRequest
func statusRequest() (*VMStatus, *cli.ExitError) {
user := getUser()
req, err := http.NewRequest("GET", "http://127.0.0.1:1050/status", nil)
if err != nil {
return nil, cli.NewExitError(err.Error(), 1)
}
req.Header.Add("X-Username", user.Name)
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, cli.NewExitError(getRequestError(err), 1)
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
if res.StatusCode < 200 || res.StatusCode >= 400 {
status := VMStatusError{}
err := decoder.Decode(&status)
if err != nil {
return nil, cli.NewExitError(err.Error(), 1)
}
return nil, cli.NewExitError(status.Message, 1)
}
status := VMStatus{}
err = decoder.Decode(&status)
if err != nil {
return nil, cli.NewExitError(err.Error(), 1)
}
return &status, nil
}
示例4: stringRequest
func stringRequest(action string) *cli.ExitError {
user := getUser()
req, err := http.NewRequest("POST", fmt.Sprintf("http://127.0.0.1:1050/%s", action), nil)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
req.Header.Add("X-Username", user.Name)
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
code := 0
if res.StatusCode < 200 || res.StatusCode >= 400 {
code = 1
}
return cli.NewExitError(string(body), code)
}
示例5: execListCommand
// Executes the "list" command
func execListCommand(c *cli.Context) error {
klient := newEtcdMinionClientFromFlags(c)
cFlag := c.String("with-classifier")
minions, err := parseClassifierPattern(klient, cFlag)
// Ignore errors about missing minion directory
if err != nil {
if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
return cli.NewExitError(err.Error(), 1)
}
}
if len(minions) == 0 {
return nil
}
table := uitable.New()
table.MaxColWidth = 80
table.AddRow("MINION", "NAME")
for _, minion := range minions {
name, err := klient.MinionName(minion)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
table.AddRow(minion, name)
}
fmt.Println(table)
return nil
}
示例6: execLastseenCommand
// Executes the "lastseen" command
func execLastseenCommand(c *cli.Context) error {
client := newEtcdMinionClientFromFlags(c)
cFlag := c.String("with-classifier")
minions, err := parseClassifierPattern(client, cFlag)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
table := uitable.New()
table.MaxColWidth = 80
table.AddRow("MINION", "LASTSEEN")
for _, minion := range minions {
lastseen, err := client.MinionLastseen(minion)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
table.AddRow(minion, time.Unix(lastseen, 0))
}
fmt.Println(table)
return nil
}
示例7: execQueueCommand
// Executes the "queue" command
func execQueueCommand(c *cli.Context) error {
if len(c.Args()) == 0 {
return cli.NewExitError(errNoMinion.Error(), 64)
}
minion := uuid.Parse(c.Args()[0])
if minion == nil {
return cli.NewExitError(errInvalidUUID.Error(), 64)
}
klient := newEtcdMinionClientFromFlags(c)
// Ignore errors about missing queue directory
queue, err := klient.MinionTaskQueue(minion)
if err != nil {
if eerr, ok := err.(client.Error); !ok || eerr.Code != client.ErrorCodeKeyNotFound {
return cli.NewExitError(err.Error(), 1)
}
}
if len(queue) == 0 {
return nil
}
table := uitable.New()
table.MaxColWidth = 40
table.AddRow("TASK", "STATE", "RECEIVED")
for _, t := range queue {
table.AddRow(t.ID, t.State, time.Unix(t.TimeReceived, 0))
}
fmt.Println(table)
return nil
}
示例8: TestProcess
func TestProcess(t *testing.T) {
passwd := "pass"
url1, _ := soap.ParseURL("127.0.0.1")
url2, _ := soap.ParseURL("root:@127.0.0.1")
url3, _ := soap.ParseURL("line:[email protected]")
url4, _ := soap.ParseURL("root:[email protected]")
result, _ := url.Parse("https://root:[email protected]/sdk")
passEmpty := ""
result1, _ := url.Parse("https://root:@127.0.0.1/sdk")
tests := []struct {
URL *url.URL
User string
Password *string
err error
result *url.URL
}{
{nil, "", nil, cli.NewExitError("--target argument must be specified", 1), nil},
{nil, "root", nil, cli.NewExitError("--target argument must be specified", 1), nil},
{nil, "root", &passwd, cli.NewExitError("--target argument must be specified", 1), nil},
{url1, "root", &passwd, nil, result},
{url4, "", nil, nil, result},
{url3, "root", &passwd, nil, result},
{url2, "", &passwd, nil, result},
{url1, "root", &passEmpty, nil, result1},
}
for _, test := range tests {
target := NewTarget()
target.URL = test.URL
target.User = test.User
target.Password = test.Password
if target.URL != nil {
t.Logf("Before processing, url: %s", target.URL.String())
}
e := target.HasCredentials()
if test.err != nil {
if e == nil {
t.Errorf("Empty error")
}
if e.Error() != test.err.Error() {
t.Errorf("Unexpected error message: %s", e.Error())
}
} else if e != nil {
t.Errorf("Unexpected error %s", e.Error())
} else {
if target.URL != test.URL {
t.Errorf("unexpected result url: %s", target.URL.String())
} else {
t.Logf("result url: %s", target.URL.String())
}
}
}
}
示例9: ensureRoot
func ensureRoot() *cli.ExitError {
if uid := os.Geteuid(); uid != 0 {
return cli.NewExitError("This command requires sudo", 1)
}
if uid := os.Getenv("SUDO_UID"); uid == "" {
return cli.NewExitError("This command requires sudo", 1)
}
return nil
}
示例10: validate
func validate(ip string, port int, c *cli.Context) *cli.ExitError {
if strings.TrimSpace(ip) == "" {
return cli.NewExitError("IP address is required. `hdp -h` for usage info.", 1)
}
if net.ParseIP(ip) == nil {
return cli.NewExitError("Invalid IP address", 1)
}
if port < 0 || port > 65535 {
return cli.NewExitError("Invalid port", 2)
}
return nil
}
示例11: runCleanup
func runCleanup(hostname, home string) *cli.ExitError {
exe, err := osext.Executable()
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
output, err := exec.Command("sudo", exe, "cleanup", "--hostname", hostname, "--home", home).Output()
code := 0
if err != nil {
code = 1
}
return cli.NewExitError(string(output), code)
}
示例12: execServeCommand
// Executes the "serve" command
func execServeCommand(c *cli.Context) error {
name, err := os.Hostname()
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
concurrency := c.Int("concurrency")
if concurrency < 0 {
concurrency = runtime.NumCPU()
}
if c.String("siterepo") == "" {
return cli.NewExitError(errNoSiteRepo.Error(), 64)
}
nameFlag := c.String("name")
if nameFlag != "" {
name = nameFlag
}
etcdCfg := etcdConfigFromFlags(c)
minionCfg := &minion.EtcdMinionConfig{
Concurrency: concurrency,
Name: name,
SiteRepo: c.String("siterepo"),
EtcdConfig: etcdCfg,
}
m, err := minion.NewEtcdMinion(minionCfg)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
// Channel on which the shutdown signal is sent
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
// Start minion
err = m.Serve()
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
// Block until a shutdown signal is received
<-quit
m.Stop()
return nil
}
示例13: ProjectPull
// ProjectPull pulls images for services.
func ProjectPull(p project.APIProject, c *cli.Context) error {
err := p.Pull(context.Background(), c.Args()...)
if err != nil && !c.Bool("ignore-pull-failures") {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
示例14: ProjectKill
// ProjectKill forces stop service containers.
func ProjectKill(p project.APIProject, c *cli.Context) error {
err := p.Kill(context.Background(), c.String("signal"), c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
示例15: ProjectStop
// ProjectStop stops all services.
func ProjectStop(p project.APIProject, c *cli.Context) error {
err := p.Stop(context.Background(), c.Int("timeout"), c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}