Skip to content

Commit

Permalink
Add ScriptName to UploadWorker (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejcx authored Dec 12, 2018
1 parent 472d6e6 commit 381cf9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ func ListWorkerRoutes(api *cloudflare.API, ZoneId string) (resp interface{}, err
return
}

func UploadWorker(api *cloudflare.API, ZoneId string, Script string) (resp interface{}, err error) {
func UploadWorker(api *cloudflare.API, ZoneId, Script, ScriptName string) (resp interface{}, err error) {
s := Script
if len(Script) != 0 {
if Script[0] == '@' {
Expand All @@ -1177,9 +1177,13 @@ func UploadWorker(api *cloudflare.API, ZoneId string, Script string) (resp inter
s = string(fileScript)
}
}
resp, err = api.UploadWorker(&cloudflare.WorkerRequestParams{
wrp := &cloudflare.WorkerRequestParams{
ZoneID: ZoneId,
}, s)
}
if ScriptName != "" {
wrp.ScriptName = ScriptName
}
resp, err = api.UploadWorker(wrp, s)
return
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/autogenerated.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var (
Disable bool
RouteId string
Script string
ScriptName string
ActorIp string
ActorEmail string
Id string
Expand Down Expand Up @@ -1973,6 +1974,8 @@ func init() {
UploadWorker.Flags().StringVar(&Script, "script", "", "The raw worker code to run at the edge. @ to read code from a file. - to read from stdin")
UploadWorker.MarkFlagRequired("script")

UploadWorker.Flags().StringVar(&ScriptName, "script-name", "", "The worker script name associated with the worker")

var UploadOrganizationWorker = &cobra.Command{
Use: "upload-organization-worker",
Short: "Upload a Cloudflare Worker associated with your Organization",
Expand Down Expand Up @@ -2545,7 +2548,7 @@ func Run(cmd *cobra.Command, args []string, name string, api *cloudflare.API) (r
case "ListWorkerRoutes":
resp, err = ListWorkerRoutes(api, ZoneId)
case "UploadWorker":
resp, err = UploadWorker(api, ZoneId, Script)
resp, err = UploadWorker(api, ZoneId, Script, ScriptName)
case "UploadOrganizationWorker":
resp, err = UploadOrganizationWorker(api, ZoneId, OrganizationId, Name, Script)
case "DeleteWorker":
Expand Down
5 changes: 5 additions & 0 deletions definitions/definitions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,11 @@
type = "string"
description = "The raw worker code to run at the edge. @ to read code from a file. - to read from stdin"
required = true
[[command.option]]
name = "script-name"
type = "string"
description = "The worker script name associated with the worker"
required = false

[[command]]
name = "upload-organization-worker"
Expand Down

0 comments on commit 381cf9b

Please sign in to comment.