-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/gebug init add network (#15)
* added prompt * added networks to render and changed template to be a little more readable * added additional generate test for network * fixed cr
- Loading branch information
1 parent
1358bee
commit 900daf7
Showing
10 changed files
with
177 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ services: | |
ports: | ||
- 8080:8080 | ||
- 8081:8081 | ||
- 40000:40000 | ||
- 40000:40000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: '3' | ||
services: | ||
gebug-my-app: | ||
build: | ||
context: .. | ||
dockerfile: .gebug/Dockerfile | ||
volumes: | ||
- ../:/src:ro | ||
ports: | ||
- 8080 | ||
networks: | ||
- frontend | ||
- backend | ||
networks: | ||
frontend: | ||
external: true | ||
backend: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: my-app | ||
output_binary: /app | ||
build_command: go build -o {{.output_binary}} | ||
runtime_image: golang:1.14 | ||
run_command: '{{.output_binary}}' | ||
debugger_port: 40000 | ||
debugger_enabled: false | ||
expose_ports: | ||
- 8080 | ||
networks: | ||
- frontend | ||
- backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,18 @@ | ||
package input | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/manifoldco/promptui" | ||
"github.com/moshebe/gebug/pkg/config" | ||
) | ||
|
||
const ( | ||
doneItem = `✔ Done` | ||
removePrefix = `✖️ ` | ||
) | ||
|
||
type PromptExposePort struct { | ||
*config.Config | ||
} | ||
|
||
func removeItem(items []string, i int) []string { | ||
if len(items) <= 1 { | ||
return []string{} | ||
} | ||
|
||
items[i] = items[len(items)-1] | ||
return items[:len(items)-1] | ||
} | ||
|
||
func addItem(items []string, item string) []string { | ||
return append(items[:len(items)-1], removePrefix+item, doneItem) | ||
} | ||
|
||
func addRemovePrefix(items []string) { | ||
n := len(items) | ||
for i := range items { | ||
if i != n-1 { | ||
items[i] = removePrefix + items[i] | ||
} | ||
} | ||
} | ||
|
||
func cleanResults(items []string) []string { | ||
items = items[:len(items)-1] | ||
for i := range items { | ||
items[i] = strings.Replace(items[i], removePrefix, "", 1) | ||
} | ||
return items | ||
} | ||
|
||
func (p *PromptExposePort) Run() error { | ||
items := append(p.ExposePorts, doneItem) | ||
addRemovePrefix(items) | ||
|
||
var result string | ||
|
||
for result != doneItem { | ||
prompt := &promptui.SelectWithAdd{ | ||
Label: "Define ports to expose. Press existing choices to delete (e.g: 8080[:8080])", | ||
Items: items, | ||
AddLabel: "Add port", | ||
} | ||
|
||
cleanResults(items) | ||
var err error | ||
var index int | ||
index, result, err = prompt.Run() | ||
if err != nil { | ||
return err | ||
} | ||
if result == doneItem { | ||
continue | ||
} | ||
|
||
if index < 0 { | ||
items = addItem(items, result) | ||
} else { | ||
items = removeItem(items, index) | ||
} | ||
} | ||
|
||
p.ExposePorts = cleanResults(items) | ||
return nil | ||
prompt := NewSelectWithAddAndRemove(&p.ExposePorts, &promptui.SelectWithAdd{ | ||
Label: "Define ports to expose. Press existing choices to delete (e.g: 8080[:8080])", | ||
AddLabel: "Add port", | ||
}) | ||
return prompt.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package input | ||
|
||
import ( | ||
"github.com/manifoldco/promptui" | ||
"github.com/moshebe/gebug/pkg/config" | ||
) | ||
|
||
type PromptNetworks struct { | ||
*config.Config | ||
} | ||
|
||
func (p *PromptNetworks) Run() error { | ||
prompt := NewSelectWithAddAndRemove(&p.Networks, &promptui.SelectWithAdd{ | ||
Label: "Add networks or leave empty to create a new network", | ||
AddLabel: "Add network", | ||
}) | ||
return prompt.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package input | ||
|
||
import ( | ||
"github.com/manifoldco/promptui" | ||
"strings" | ||
) | ||
|
||
const ( | ||
defaultDoneItem = `✔ Done` | ||
defaultRemovePrefix = `✖️ ` | ||
) | ||
|
||
type SelectWithAddAndRemove struct { | ||
prompt *promptui.SelectWithAdd | ||
field *[]string | ||
doneItem string | ||
removePrefix string | ||
} | ||
|
||
func NewSelectWithAddAndRemove(field *[]string, prompt *promptui.SelectWithAdd) *SelectWithAddAndRemove { | ||
return &SelectWithAddAndRemove{ | ||
prompt: prompt, | ||
field: field, | ||
doneItem: defaultDoneItem, | ||
removePrefix: defaultRemovePrefix, | ||
} | ||
} | ||
|
||
func (s *SelectWithAddAndRemove) remove(items []string, i int) []string { | ||
if len(items) <= 1 { | ||
return []string{} | ||
} | ||
|
||
items[i] = items[len(items)-1] | ||
return items[:len(items)-1] | ||
} | ||
|
||
func (s *SelectWithAddAndRemove) add(items []string, item string) []string { | ||
return append(items[:len(items)-1], s.removePrefix+item, s.doneItem) | ||
} | ||
|
||
func (s *SelectWithAddAndRemove) appendRemovePrefix(items []string) { | ||
n := len(items) | ||
for i := range items { | ||
if i != n-1 { | ||
items[i] = s.removePrefix + items[i] | ||
} | ||
} | ||
} | ||
|
||
func (s *SelectWithAddAndRemove) cleanResults(items []string) []string { | ||
items = items[:len(items)-1] | ||
for i := range items { | ||
items[i] = strings.Replace(items[i], s.removePrefix, "", 1) | ||
} | ||
return items | ||
} | ||
|
||
func (s *SelectWithAddAndRemove) Run() error { | ||
items := append(*s.field, s.doneItem) | ||
s.appendRemovePrefix(items) | ||
|
||
var result string | ||
|
||
for result != s.doneItem { | ||
var err error | ||
var index int | ||
s.prompt.Items = items | ||
index, result, err = s.prompt.Run() | ||
if err != nil { | ||
return err | ||
} | ||
if result == s.doneItem { | ||
continue | ||
} | ||
|
||
if index < 0 { | ||
items = s.add(items, result) | ||
} else { | ||
items = s.remove(items, index) | ||
} | ||
} | ||
|
||
*s.field = s.cleanResults(items) | ||
return nil | ||
} |