本文整理汇总了Golang中github.com/codegangsta/cli.Context.NArg方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.NArg方法的具体用法?Golang Context.NArg怎么用?Golang Context.NArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.NArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upload
func upload(c *cli.Context) {
if c.NArg() < 2 || c.NArg() > 3 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
localPath := c.Args().Get(0)
versionDetails, err := utils.CreateVersionDetails(c.Args().Get(1))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
uploadPath := c.Args().Get(2)
if strings.HasPrefix(uploadPath, "/") {
uploadPath = uploadPath[1:]
}
uploadFlags, err := createUploadFlags(c)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
uploaded, failed, err := commands.Upload(versionDetails, localPath, uploadPath, uploadFlags)
cliutils.ExitOnErr(err)
if failed > 0 {
if uploaded > 0 {
cliutils.Exit(cliutils.ExitCodeWarning, "")
}
cliutils.Exit(cliutils.ExitCodeError, "")
}
}
示例2: getArguments
func getArguments(c *cli.Context) (string, string) {
if c.NArg() != 2 {
showError(c, "render arguments must be exactly 2 (input scene file and output image file)")
}
arguments := []string(c.Args())
return arguments[0], arguments[1]
}
示例3: logs
func logs(c *cli.Context) {
bintrayDetails, err := createBintrayDetails(c, true)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
if c.NArg() == 1 {
packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0))
cliutils.ExitOnErr(err)
err = commands.LogsList(packageDetails, bintrayDetails)
cliutils.ExitOnErr(err)
} else if c.NArg() == 3 {
if c.Args().Get(0) == "download" {
packageDetails, err := utils.CreatePackageDetails(c.Args().Get(1))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.DownloadLog(packageDetails, c.Args().Get(2), bintrayDetails)
cliutils.ExitOnErr(err)
} else {
cliutils.Exit(cliutils.ExitCodeError, "Unkown argument "+c.Args().Get(0)+". "+cliutils.GetDocumentationMessage())
}
} else {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
}
示例4: DeletePolicy
func DeletePolicy(c *cli.Context) error {
unix, target, err := processClientTarget(c)
if err != nil {
return err
}
if unix {
return noUnix
} else {
var name string
if c.NArg() > 0 {
name = c.Args()[0]
}
client := &http.Client{}
req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/policy/%s", target, name), nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("%s", body)
}
return nil
}
示例5: handleStage
func handleStage(ctx *cli.Context, client *daemon.Client) error {
filePath, err := filepath.Abs(ctx.Args().First())
if err != nil {
return ExitCode{
UnknownError,
fmt.Sprintf("Unable to make abs path: %v: %v", filePath, err),
}
}
// Assume "/file.png" for file.png as repo path, if none given.
repoPath := "/" + filepath.Base(filePath)
if ctx.NArg() > 1 {
repoPath = ctx.Args()[1]
}
if err := client.Stage(filePath, repoPath); err != nil {
return ExitCode{
UnknownError,
fmt.Sprintf("Could not stage file: %v: %v", filePath, err),
}
}
fmt.Println(repoPath)
return nil
}
示例6: deleteVersion
func deleteVersion(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
bintrayDetails, err := createBintrayDetails(c, true)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
if !c.Bool("quiet") {
var confirm string
fmt.Print("Delete version " + versionDetails.Version +
" of package " + versionDetails.Package + "? (y/n): ")
fmt.Scanln(&confirm)
if !cliutils.ConfirmAnswer(confirm) {
return
}
}
err = commands.DeleteVersion(versionDetails, bintrayDetails)
cliutils.ExitOnErr(err)
}
示例7: CheckAutocomplete
func CheckAutocomplete(commands []string, c *cli.Context) {
if c.NArg() > 0 {
return
}
for _, command := range commands {
fmt.Println(command)
}
}
示例8: appSwitchAction
func appSwitchAction(c *cli.Context) {
if c.NArg() != 1 {
log.Fatal("Usage: lean app switch <app-name>")
}
appName := c.Args()[0]
utils.CheckError(apps.SwitchApp("", appName))
}
示例9: rmReplica
func rmReplica(c *cli.Context) error {
if c.NArg() == 0 {
return errors.New("replica address is required")
}
replica := c.Args()[0]
controllerClient := getCli(c)
_, err := controllerClient.DeleteReplica(replica)
return err
}
示例10: buildDistributeCmd
func buildDistributeCmd(c *cli.Context) {
if c.NArg() != 3 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
buildDistributeFlags, err := createBuildDistributionFlags(c)
if err != nil {
cliutils.ExitOnErr(err)
}
err = commands.BuildDistribute(c.Args().Get(0), c.Args().Get(1), c.Args().Get(2), buildDistributeFlags)
cliutils.ExitOnErr(err)
}
示例11: signUrl
func signUrl(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
urlSigningDetails, err := utils.CreatePathDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
urlSigningFlags, err := createUrlSigningFlags(c)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.SignVersion(urlSigningDetails, urlSigningFlags)
cliutils.ExitOnErr(err)
}
示例12: updatePackage
func updatePackage(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
packageFlags, err := createPackageFlags(c)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.UpdatePackage(packageDetails, packageFlags)
cliutils.ExitOnErr(err)
}
示例13: gpgSignVersion
func gpgSignVersion(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
flags, err := createBintrayDetails(c, true)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.GpgSignVersion(versionDetails, c.String("passphrase"), flags)
cliutils.ExitOnErr(err)
}
示例14: publishVersion
func publishVersion(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
}
versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
bintrayDetails, err := createBintrayDetails(c, true)
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.PublishVersion(versionDetails, bintrayDetails)
cliutils.ExitOnErr(err)
}
示例15: createVersion
func createVersion(c *cli.Context) {
if c.NArg() != 1 {
cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments "+cliutils.GetDocumentationMessage())
}
versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
versionFlags, err := createVersionFlags(c, "")
if err != nil {
cliutils.Exit(cliutils.ExitCodeError, err.Error())
}
err = commands.CreateVersion(versionDetails, versionFlags)
cliutils.ExitOnErr(err)
}