Skip to content

Commit

Permalink
Enhance command completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Icikowski committed Feb 4, 2022
1 parent 5249d88 commit f5b40bd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions application/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var MyApps *cliv2.App = &cliv2.App{
Usage: "Installs the application(s)",
Before: allChecks,
Action: install,
BashComplete: installCompletion,
HideHelpCommand: true,
},
{
Expand All @@ -56,13 +57,15 @@ var MyApps *cliv2.App = &cliv2.App{
Action: update,
Flags: updateFlags,
HideHelpCommand: true,
BashComplete: updateCompletion,
},
{
Name: "uninstall",
Usage: "Uninstalls the application",
Before: allChecks,
Action: uninstall,
Flags: uninstallFlags,
BashComplete: uninstallCompletion,
HideHelpCommand: true,
},
{
Expand Down Expand Up @@ -90,6 +93,7 @@ var MyApps *cliv2.App = &cliv2.App{
Usage: "Shows the contents of the repository",
Before: basicChecks,
Action: showRepo,
BashComplete: singleRepositoryCompletion,
HideHelpCommand: true,
},
{
Expand All @@ -98,13 +102,15 @@ var MyApps *cliv2.App = &cliv2.App{
Usage: "Removes the repository",
Before: allChecks,
Action: removeRepos,
BashComplete: multipleRepositoriesCompletion,
HideHelpCommand: true,
},
{
Name: "default",
Usage: "Gets/sets the default repository",
Before: basicChecks,
Action: defaultRepo,
BashComplete: singleRepositoryCompletion,
HideHelpCommand: true,
},
},
Expand Down
14 changes: 14 additions & 0 deletions application/cli/cmd_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ import (
"icikowski.pl/myapps/types"
)

func installCompletion(ctx *cliv2.Context) {
repos := config.GetRepositories()
deployments := config.GetDeployments()

for _, repo := range repos {
for _, app := range repo.Contents {
if deployments.Exists(repo.Name, app.Name) {
continue
}
fmt.Printf("%s/%s\n", repo.Name, app.Name)
}
}
}

func install(ctx *cliv2.Context) error {
args := ctx.Args()
if !args.Present() {
Expand Down
13 changes: 13 additions & 0 deletions application/cli/cmd_repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ var addReposFlags = []cliv2.Flag{
},
}

func multipleRepositoriesCompletion(ctx *cliv2.Context) {
for _, repo := range config.GetRepositories() {
fmt.Println(repo.Name)
}
}

func singleRepositoryCompletion(ctx *cliv2.Context) {
if ctx.NArg() != 0 {
return
}
multipleRepositoriesCompletion(ctx)
}

func addRepos(ctx *cliv2.Context) error {
args := ctx.Args()
if !args.Present() {
Expand Down
6 changes: 6 additions & 0 deletions application/cli/cmd_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (

var uninstallFlags = []cliv2.Flag{}

func uninstallCompletion(ctx *cliv2.Context) {
for _, deployment := range config.GetDeployments() {
fmt.Println(deployment.String())
}
}

func uninstall(ctx *cliv2.Context) error {
args := ctx.Args()
if !args.Present() {
Expand Down
9 changes: 9 additions & 0 deletions application/cli/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ var updateFlags = []cliv2.Flag{
},
}

func updateCompletion(ctx *cliv2.Context) {
if ctx.IsSet("all") {
return
}
for _, deployment := range config.GetDeployments() {
fmt.Println(deployment.String())
}
}

func update(ctx *cliv2.Context) error {
repos := config.GetRepositories()
deployments := config.GetDeployments()
Expand Down

0 comments on commit f5b40bd

Please sign in to comment.