Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/appdev #1204

Merged
merged 6 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
ArgAppLogType = "type"
// ArgAppDeployment is the deployment ID.
ArgAppDeployment = "deployment"
// ArgAppDevLinkConfig is the path to the app dev link config.
ArgAppDevLinkConfig = "link-config"
// ArgAppLogFollow follow logs.
ArgAppLogFollow = "follow"
// ArgAppLogTail tail logs.
Expand Down Expand Up @@ -110,10 +112,14 @@ const (
ArgImagePublic = "public"
// ArgImageSlug is an image slug argument.
ArgImageSlug = "image-slug"
// ArgInteractive is the argument to enable an interactive CLI.
ArgInteractive = "interactive"
// ArgIPAddress is an IP address argument.
ArgIPAddress = "ip-address"
// ArgDropletName is a droplet name argument.
ArgDropletName = "droplet-name"
// ArgEnvFile is an environment file to load variables from.
ArgEnvFile = "env-file"
// ArgResizeDisk is a resize disk argument.
ArgResizeDisk = "resize-disk"
// ArgSnapshotName is a snapshot name argument.
Expand Down Expand Up @@ -212,6 +218,8 @@ const (
ArgTag = "tag"
//ArgTemplate is template format
ArgTemplate = "template"
// ArgTimeout is a timeout duration
ArgTimeout = "timeout"
// ArgVersion is the version of the command to use
ArgVersion = "version"
// ArgVerbose enables verbose output
Expand Down Expand Up @@ -341,6 +349,8 @@ const (

// ArgReadWrite indicates a generated token should be read/write.
ArgReadWrite = "read-write"
// ArgRegistryName indicates the name of the registry.
ArgRegistryName = "registry-name"
// ArgRegistryExpirySeconds indicates the length of time the token will be valid in seconds.
ArgRegistryExpirySeconds = "expiry-seconds"
// ArgSubscriptionTier is a subscription tier slug.
Expand Down
72 changes: 72 additions & 0 deletions cmd/charm-test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"fmt"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/digitalocean/doctl/commands/charm"
)

func main() {
fmt.Println(
charm.Checkmark, charm.CheckmarkSuccess,
)

fmt.Println(
charm.TextSuccess.WithString("woo!"), charm.TextSuccess.S("woo 2!"),
)

if err := charm.TemplatePrint(heredoc.Doc(`
--- template ---
This is an example template.

Another line.

{{ success "maybe some success output" }}
{{ success checkmark }} just the checkmark.
{{ success (join " " (checkmark) "good job!") }}
{{ error (join " " (checkmark) "we're both confused.") }}
{{ warning "try again?" }}
{{ error (join " " (crossmark) "there we go.") }}

{{ success (bold "full send let's go!!!!") }}
{{ bold (success "full send let's go!!!!") }}

{{ bold (underline "underline behaves very strangely") }}
{{ underline (bold "underline behaves very strangely") }}

{{ success (underline "underline behaves very strangely") }}
{{ underline (success "underline behaves very strangely") }}

{{ newTextBox.Success.S "i'm in a box!" }}
`), nil); err != nil {
panic(err)
}

img := "yeet/yote:dev"
dur := 23*time.Minute + 37*time.Second
fmt.Fprintf(
charm.NewTextBox().Success(),
"%s Successfully built %s in %s",
charm.CheckmarkSuccess,
charm.TextSuccess.S(img),
charm.TextWarning.S(dur.Truncate(time.Second).String()),
)

if err := charm.TemplateBufferedE(charm.NewTextBox().Success(), heredoc.Doc(`
{{ success checkmark }} Successfully built {{ success .img }} in {{ warning (duration .dur) }}`,
), map[string]any{
"img": img,
"dur": dur,
}); err != nil {
panic(err)
}

charm.TemplateBuffered(charm.NewTextBox().Success(), heredoc.Doc(`
{{ success checkmark }} Successfully built {{ success .img }} in {{ warning (duration .dur) }}`,
), map[string]any{
"img": img,
"dur": dur,
})
}
2 changes: 2 additions & 0 deletions commands/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func Apps() *Command {
},
}

cmd.AddCommand(AppsDev())

create := CmdBuilder(
cmd,
RunAppsCreate,
Expand Down
37 changes: 37 additions & 0 deletions commands/apps_charm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

import (
"fmt"
"strings"

"github.com/digitalocean/doctl/commands/charm"
"github.com/digitalocean/godo"
)

type componentListItem struct {
spec godo.AppComponentSpec
}

func (i componentListItem) Title() string {
return i.spec.GetName()
}
func (i componentListItem) Description() string {
desc := []string{
snakeToTitle(string(i.spec.GetType())) + " component",
}

if buildable, ok := i.spec.(godo.AppBuildableComponentSpec); ok {
if sourceDir := buildable.GetSourceDir(); sourceDir != "" {
desc = append(desc, "located in ./"+charm.TextHighlight.S(sourceDir))
}
}

return strings.Join(desc, "\n")
}
func (i componentListItem) FilterValue() string {
return i.spec.GetName()
}

func snakeToTitle(s string) string {
return strings.Title(strings.ReplaceAll(strings.ToLower(fmt.Sprint(s)), "_", " "))
}
Loading