Skip to content

Commit

Permalink
Added ufw completer (#2708)
Browse files Browse the repository at this point in the history
* Added ufw completer

* code fix

* code fix

* Update completers/ufw_completer/cmd/actions/profile.go

Co-authored-by: Ralf Steube <[email protected]>

---------

Co-authored-by: Ralf Steube <[email protected]>
  • Loading branch information
Saurabh825 and rsteube authored Feb 23, 2025
1 parent bbf4e89 commit 916e858
Show file tree
Hide file tree
Showing 27 changed files with 531 additions and 0 deletions.
21 changes: 21 additions & 0 deletions completers/ufw_completer/cmd/actions/profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package actions

import (
"github.com/carapace-sh/carapace"
"strings"
)

func ActionUfwProfiles() carapace.Action {
return carapace.ActionExecCommand("ufw", "app", "list")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")[1:]
var profiles []string

for _, line := range lines {
if profile := strings.TrimSpace(line); profile != "" {
profiles = append(profiles, profile, "")
}
}

return carapace.ActionValues(profiles...)
})
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/allow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var allowCmd = &cobra.Command{
Use: "allow",
Short: "add allow rule",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(allowCmd).Standalone()

rootCmd.AddCommand(allowCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var appCmd = &cobra.Command{
Use: "app",
Short: "Application profile commands",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(appCmd).Standalone()

rootCmd.AddCommand(appCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/app_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var app_defaultCmd = &cobra.Command{
Use: "default",
Short: "set default application policy",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(app_defaultCmd).Standalone()

appCmd.AddCommand(app_defaultCmd)
}
23 changes: 23 additions & 0 deletions completers/ufw_completer/cmd/app_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/ufw_completer/cmd/actions"
"github.com/spf13/cobra"
)

var app_infoCmd = &cobra.Command{
Use: "info",
Short: "show information on PROFILE",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(app_infoCmd).Standalone()

appCmd.AddCommand(app_infoCmd)

carapace.Gen(app_infoCmd).PositionalCompletion(
actions.ActionUfwProfiles(),
)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/app_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var app_listCmd = &cobra.Command{
Use: "list",
Short: "list application profiles",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(app_listCmd).Standalone()

appCmd.AddCommand(app_listCmd)
}
24 changes: 24 additions & 0 deletions completers/ufw_completer/cmd/app_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/ufw_completer/cmd/actions"
"github.com/spf13/cobra"
)

var app_updateCmd = &cobra.Command{
Use: "update",
Short: "update PROFILE",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(app_updateCmd).Standalone()

app_updateCmd.Flags().String("add-new", "", "")
appCmd.AddCommand(app_updateCmd)

carapace.Gen(app_updateCmd).PositionalCompletion(
actions.ActionUfwProfiles(),
)
}
25 changes: 25 additions & 0 deletions completers/ufw_completer/cmd/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var defaultCmd = &cobra.Command{
Use: "default",
Short: "set default policy",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(defaultCmd).Standalone()

rootCmd.AddCommand(defaultCmd)

carapace.Gen(loggingCmd).PositionalCompletion(
carapace.ActionValues(
"allow",
"deny",
"reject",
))
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "delete RULE",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(deleteCmd).Standalone()

rootCmd.AddCommand(deleteCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/deny.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var denyCmd = &cobra.Command{
Use: "deny",
Short: "add deny rule",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(denyCmd).Standalone()

rootCmd.AddCommand(denyCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var disableCmd = &cobra.Command{
Use: "disable",
Short: "disables the firewall",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(disableCmd).Standalone()

rootCmd.AddCommand(disableCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var enableCmd = &cobra.Command{
Use: "enable",
Short: "enables the firewall",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(enableCmd).Standalone()

rootCmd.AddCommand(enableCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/insert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var insertCmd = &cobra.Command{
Use: "insert",
Short: "insert RULE at NUM",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(insertCmd).Standalone()

rootCmd.AddCommand(insertCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var limitCmd = &cobra.Command{
Use: "limit",
Short: "add limit rule",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(limitCmd).Standalone()

rootCmd.AddCommand(limitCmd)
}
28 changes: 28 additions & 0 deletions completers/ufw_completer/cmd/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var loggingCmd = &cobra.Command{
Use: "logging",
Short: "set logging to LEVEL",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(loggingCmd).Standalone()

rootCmd.AddCommand(loggingCmd)

carapace.Gen(loggingCmd).PositionalCompletion(
carapace.ActionValues(
"full",
"high",
"low",
"medium",
"off",
"on",
))
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/prepend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var prependCmd = &cobra.Command{
Use: "prepend",
Short: "prepend RULE",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(prependCmd).Standalone()

rootCmd.AddCommand(prependCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/reject.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var rejectCmd = &cobra.Command{
Use: "reject",
Short: "add reject rule",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(rejectCmd).Standalone()

rootCmd.AddCommand(rejectCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/reload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var reloadCmd = &cobra.Command{
Use: "reload",
Short: "reload firewall",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(reloadCmd).Standalone()

rootCmd.AddCommand(reloadCmd)
}
18 changes: 18 additions & 0 deletions completers/ufw_completer/cmd/reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var resetCmd = &cobra.Command{
Use: "reset",
Short: "reset firewall",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(resetCmd).Standalone()

rootCmd.AddCommand(resetCmd)
}
Loading

0 comments on commit 916e858

Please sign in to comment.