Skip to content

Commit

Permalink
Feature/appdev (digitalocean#1204)
Browse files Browse the repository at this point in the history
* apps: add base scaffolding for app dev command subtree

* charm templates: change up method signatures for easier use

* only use 1.18.x in ci

* add internal package to unit test

* disable interactive mode

* only use logging pager in interactive mode

Co-authored-by: Kamal Nasser <[email protected]>
  • Loading branch information
nicktate and kamaln7 committed Sep 20, 2022
1 parent f5e6747 commit d70f8cc
Show file tree
Hide file tree
Showing 958 changed files with 121,188 additions and 1,306 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.17.x, 1.18.x ]
go-version: [ 1.18.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ docker_build:
test_unit:
@echo "==> run unit tests"
@echo ""
go test -mod=vendor ./commands/... ./do/... ./pkg/... .
go test -mod=vendor ./commands/... ./do/... ./pkg/... ./internal/... .

.PHONY: test_integration
test_integration:
Expand Down
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 @@ -343,6 +351,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

0 comments on commit d70f8cc

Please sign in to comment.