本文整理汇总了Golang中github.com/urfave/cli.NewExitError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewExitError函数的具体用法?Golang NewExitError怎么用?Golang NewExitError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewExitError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:ycaille,项目名称:gru,代码行数:29,代码来源:apply.go
示例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
}
开发者ID:vdemeester,项目名称:libcompose,代码行数:32,代码来源:app.go
示例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
}
开发者ID:nlf,项目名称:dlite,代码行数:34,代码来源:helpers.go
示例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)
}
开发者ID:nlf,项目名称:dlite,代码行数:27,代码来源:helpers.go
示例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
}
开发者ID:dnaeon,项目名称:gru,代码行数:34,代码来源:list.go
示例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
}
开发者ID:dnaeon,项目名称:gru,代码行数:27,代码来源:lastseen.go
示例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
}
开发者ID:dnaeon,项目名称:gru,代码行数:36,代码来源:queue.go
示例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())
}
}
}
}
开发者ID:vmware,项目名称:vic,代码行数:54,代码来源:target_test.go
示例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
}
开发者ID:nlf,项目名称:dlite,代码行数:11,代码来源:helpers.go
示例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
}
开发者ID:vincer,项目名称:hdp,代码行数:12,代码来源:hdp.go
示例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)
}
开发者ID:nlf,项目名称:dlite,代码行数:13,代码来源:helpers.go
示例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
}
开发者ID:dnaeon,项目名称:gru,代码行数:50,代码来源:serve.go
示例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
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:8,代码来源:app.go
示例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
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:8,代码来源:app.go
示例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
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:8,代码来源:app.go
示例16: ProjectUnpause
// ProjectUnpause unpauses service containers.
func ProjectUnpause(p project.APIProject, c *cli.Context) error {
err := p.Unpause(context.Background(), c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:8,代码来源:app.go
示例17: ProjectLog
// ProjectLog gets services logs.
func ProjectLog(p project.APIProject, c *cli.Context) error {
err := p.Log(context.Background(), c.Bool("follow"), c.Args()...)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:8,代码来源:app.go
示例18: ProjectPort
// ProjectPort prints the public port for a port binding.
func ProjectPort(p project.APIProject, c *cli.Context) error {
if len(c.Args()) != 2 {
return cli.NewExitError("Please pass arguments in the form: SERVICE PORT", 1)
}
index := c.Int("index")
protocol := c.String("protocol")
serviceName := c.Args()[0]
privatePort := c.Args()[1]
port, err := p.Port(context.Background(), index, protocol, serviceName, privatePort)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
fmt.Println(port)
return nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:18,代码来源:app.go
示例19: execGraphCommand
// Executes the "graph" command
func execGraphCommand(c *cli.Context) error {
if len(c.Args()) < 1 {
return cli.NewExitError(errNoModuleName.Error(), 64)
}
L := lua.NewState()
defer L.Close()
module := c.Args()[0]
config := &catalog.Config{
Module: module,
DryRun: true,
Logger: log.New(os.Stdout, "", log.LstdFlags),
SiteRepo: c.String("siterepo"),
L: L,
}
katalog := catalog.New(config)
resource.LuaRegisterBuiltin(L)
if err := L.DoFile(module); err != nil {
return cli.NewExitError(err.Error(), 1)
}
collection, err := resource.CreateCollection(katalog.Unsorted)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
g, err := collection.DependencyGraph()
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
g.AsDot("resources", os.Stdout)
g.Reversed().AsDot("reversed", os.Stdout)
sorted, err := g.Sort()
if err == graph.ErrCircularDependency {
circular := graph.New()
circular.AddNode(sorted...)
circular.AsDot("circular", os.Stdout)
return cli.NewExitError(graph.ErrCircularDependency.Error(), 1)
}
return nil
}
开发者ID:dnaeon,项目名称:gru,代码行数:47,代码来源:graph.go
示例20: processProxies
func (c *Create) processProxies() error {
var err error
if c.httpProxy != "" {
c.HTTPProxy, err = url.Parse(c.httpProxy)
if err != nil || c.HTTPProxy.Host == "" || c.HTTPProxy.Scheme != "http" {
return cli.NewExitError(fmt.Sprintf("Could not parse HTTP proxy - expected format http://fqnd_or_ip:port: %s", c.httpProxy), 1)
}
}
if c.httpsProxy != "" {
c.HTTPSProxy, err = url.Parse(c.httpsProxy)
if err != nil || c.HTTPSProxy.Host == "" || c.HTTPSProxy.Scheme != "https" {
return cli.NewExitError(fmt.Sprintf("Could not parse HTTPS proxy - expected format https://fqnd_or_ip:port: %s", c.httpsProxy), 1)
}
}
return nil
}
开发者ID:vmware,项目名称:vic,代码行数:18,代码来源:create.go
注:本文中的github.com/urfave/cli.NewExitError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论