Skip to content

Commit

Permalink
bloop: added completions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Nov 25, 2024
1 parent 2630091 commit beb372d
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 34 deletions.
12 changes: 7 additions & 5 deletions completers/bloop_completer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM alpine
FROM ubuntu

RUN apt-get update \
&& apt-get install -y bash curl elvish git scala

RUN apk add --no-cache curl gcompat
RUN apk add --no-cache \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
elvish
RUN curl -fL "https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz" \
| gzip -d > /usr/bin/cs \
&& chmod +x /usr/bin/cs

RUN cs setup -y
RUN cs install bloop --only-prebuilt=true

ENV PATH="$PATH:/root/.local/share/coursier/bin"
RUN bloop
ENTRYPOINT [ "bash" ]
10 changes: 6 additions & 4 deletions completers/bloop_completer/cmd/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

Expand All @@ -15,13 +16,14 @@ func init() {
carapace.Gen(autocompleteCmd).Standalone()

autocompleteCmd.Flags().String("command", "", "")
autocompleteCmd.Flags().String("format", "", "")
autocompleteCmd.Flags().String("mode", "", "")
autocompleteCmd.Flags().String("format", "", "output format")
autocompleteCmd.Flags().String("mode", "", "completion mode")
autocompleteCmd.Flags().String("project", "", "")
rootCmd.AddCommand(autocompleteCmd)

// TODO flag completion
carapace.Gen(autocompleteCmd).FlagCompletion(carapace.ActionMap{
"format": carapace.ActionValues("bash", "fish", "zsh"),
"format": carapace.ActionValues("bash", "fish", "zsh"),
"mode": carapace.ActionValues("commands", "mainsfqcn", "projects", "project-commands", "protocols", "reporters", "testsfqcn"),
"project": bloop.ActionProjects(),
})
}
3 changes: 2 additions & 1 deletion completers/bloop_completer/cmd/bsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/net"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +27,7 @@ func init() {
"host": net.ActionHosts(),
"pipe-name": carapace.ActionFiles(),
"port": net.ActionPorts(),
"protocol": carapace.ActionValues(), // TODO
"protocol": bloop.ActionProtocols(),
"socket": carapace.ActionFiles(),
})
}
12 changes: 10 additions & 2 deletions completers/bloop_completer/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var cleanCmd = &cobra.Command{
Use: "clean",
Use: "clean <project>",
Short: "clean compilation caches",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -23,5 +24,12 @@ func init() {

cleanCmd.MarkFlagsMutuallyExclusive("include-dependencies", "propagate")

// TODO completion
carapace.Gen(cleanCmd).FlagCompletion(carapace.ActionMap{
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
})

carapace.Gen(cleanCmd).PositionalAnyCompletion(
bloop.ActionProjects().FilterArgs(),
)
}
13 changes: 11 additions & 2 deletions completers/bloop_completer/cmd/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var compileCmd = &cobra.Command{
Use: "compile",
Use: "compile <project>",
Short: "compile projects",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -23,5 +24,13 @@ func init() {
compileCmd.Flags().BoolP("watch", "w", false, "run the command when projects' source files change")
rootCmd.AddCommand(compileCmd)

// TODO completion
carapace.Gen(compileCmd).FlagCompletion(carapace.ActionMap{
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
"reporter": bloop.ActionReporters(),
})

carapace.Gen(compileCmd).PositionalAnyCompletion(
bloop.ActionProjects().FilterArgs(),
)
}
14 changes: 9 additions & 5 deletions completers/bloop_completer/cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var consoleCmd = &cobra.Command{
Use: "console",
Use: "console <project>",
Short: "start console",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -26,14 +27,17 @@ func init() {
consoleCmd.Flags().String("reporter", "", "pick reporter to show compilation messages")
rootCmd.AddCommand(consoleCmd)

// TODO completion
carapace.Gen(consoleCmd).FlagCompletion(carapace.ActionMap{
"ammonite-version": carapace.ActionValues(),
"args": carapace.ActionValues(),
"out-file": carapace.ActionFiles(),
"project": carapace.ActionValues(),
"projects": carapace.ActionValues(),
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
"repl": carapace.ActionValues("scalac", "ammonite"),
"reporter": carapace.ActionValues(),
"reporter": bloop.ActionReporters(),
})

carapace.Gen(consoleCmd).PositionalAnyCompletion(
bloop.ActionProjects().FilterArgs(),
)
}
12 changes: 8 additions & 4 deletions completers/bloop_completer/cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var linkCmd = &cobra.Command{
Use: "link",
Use: "link <link>",
Short: "link projects",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -24,11 +25,14 @@ func init() {
linkCmd.Flags().BoolP("watch", "w", false, "run the command whenever projects' source files change")
rootCmd.AddCommand(linkCmd)

// TODO completion
carapace.Gen(linkCmd).FlagCompletion(carapace.ActionMap{
"main": carapace.ActionValues(),
"optimize": carapace.ActionValues("debug", "release"),
"project": carapace.ActionValues(),
"projects": carapace.ActionValues(),
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
})

carapace.Gen(linkCmd).PositionalAnyCompletion(
bloop.ActionProjects().FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/bloop_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"config-dir": carapace.ActionDirectories(),
"debug": carapace.ActionValues("all", "file-watching", "compilation", "test", "bsp", "link"), // TODO list?
"debug": carapace.ActionValues("all", "file-watching", "compilation", "test", "bsp", "link"),
})

}
14 changes: 9 additions & 5 deletions completers/bloop_completer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var runCmd = &cobra.Command{
Use: "run",
Use: "run <project>",
Short: "run a project",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -26,13 +27,16 @@ func init() {
runCmd.Flags().BoolP("watch", "w", false, "run the command whenever projects' source files change")
rootCmd.AddCommand(runCmd)

// TODO completion
carapace.Gen(runCmd).FlagCompletion(carapace.ActionMap{
"args": carapace.ActionValues(),
"main": carapace.ActionValues(),
"optimize": carapace.ActionValues("debug", "release"),
"project": carapace.ActionValues(),
"projects": carapace.ActionValues(),
"reporter": carapace.ActionValues(),
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
"reporter": bloop.ActionReporters(),
})

carapace.Gen(runCmd).PositionalAnyCompletion(
bloop.ActionProjects().FilterArgs(),
)
}
14 changes: 9 additions & 5 deletions completers/bloop_completer/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bloop"
"github.com/spf13/cobra"
)

var testCmd = &cobra.Command{
Use: "test",
Use: "test <project>",
Short: "run tests",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -28,12 +29,15 @@ func init() {
testCmd.Flags().BoolP("watch", "w", false, "run the command when projects' source files change")
rootCmd.AddCommand(testCmd)

// TODO completion
carapace.Gen(testCmd).FlagCompletion(carapace.ActionMap{
"args": carapace.ActionValues(),
"only": carapace.ActionValues(),
"project": carapace.ActionValues(),
"projects": carapace.ActionValues(),
"reporter": carapace.ActionValues(),
"project": bloop.ActionProjects(),
"projects": bloop.ActionProjects(),
"reporter": bloop.ActionReporters(),
})

carapace.Gen(testCmd).PositionalAnyCompletion(
bloop.ActionProjects(),
)
}
46 changes: 46 additions & 0 deletions pkg/actions/tools/bloop/bloop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bloop

import (
"strings"

"github.com/carapace-sh/carapace"
)

func autocomplete(mode string) carapace.Action {
return carapace.ActionExecCommand("bloop", "autocomplete", "--format", "fish", "--mode", mode)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

for _, line := range lines {
if line != "" {
value, description, _ := strings.Cut(line, "\t")
vals = append(vals, value, description)
}
}
return carapace.ActionValuesDescribed(vals...)
})
}

// ActionProjects completes projects
//
// one
// two
func ActionProjects() carapace.Action {
return autocomplete("projects").Tag("projects")
}

// ActionProtocols completes protocols
//
// local
// tcp
func ActionProtocols() carapace.Action {
return autocomplete("protocols").Tag("protocols")
}

// ActionReporters completes ActionReporters
//
// scalac
// bloop
func ActionReporters() carapace.Action {
return autocomplete("reporters").Tag("reporters")
}

0 comments on commit beb372d

Please sign in to comment.