Added ufw completer (#2708)

* Added ufw completer

* code fix

* code fix

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

Co-authored-by: Ralf Steube <rsteube@users.noreply.github.com>

---------

Co-authored-by: Ralf Steube <rsteube@users.noreply.github.com>
This commit is contained in:
Saurabh Kushwah 2025-02-24 02:22:32 +05:30 committed by GitHub
parent bbf4e89fd6
commit 916e858d1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 531 additions and 0 deletions

View File

@ -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...)
})
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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(),
)
}

View File

@ -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)
}

View File

@ -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(),
)
}

View File

@ -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",
))
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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",
))
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -0,0 +1,25 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "ufw",
Short: "program for managing a netfilter firewall",
Long: "https://launchpad.net/ufw",
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().Bool("dry-run", false, "don't modify anything, just show the changes")
rootCmd.Flags().Bool("force", false, "")
rootCmd.Flags().BoolP("help", "h", false, "show help message and exit")
rootCmd.Flags().Bool("version", false, "show program's version number and exit")
}

View File

@ -0,0 +1,18 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var routeCmd = &cobra.Command{
Use: "route",
Short: "add route RULE",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(routeCmd).Standalone()
rootCmd.AddCommand(routeCmd)
}

View File

@ -0,0 +1,18 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var route_deleteCmd = &cobra.Command{
Use: "delete",
Short: "delete route RULE",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(route_deleteCmd).Standalone()
routeCmd.AddCommand(route_deleteCmd)
}

View File

@ -0,0 +1,18 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var route_insertCmd = &cobra.Command{
Use: "insert",
Short: "insert route RULE at NUM",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(route_insertCmd).Standalone()
routeCmd.AddCommand(route_insertCmd)
}

View File

@ -0,0 +1,30 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var showCmd = &cobra.Command{
Use: "show",
Short: "show firewall report",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(showCmd).Standalone()
rootCmd.AddCommand(showCmd)
carapace.Gen(showCmd).PositionalCompletion(
carapace.ActionValues(
"added",
"after-rules",
"before-rules",
"builtins",
"listening",
"logging-rules",
"raw",
"user-rules",
))
}

View File

@ -0,0 +1,24 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "show firewall status",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(statusCmd).Standalone()
rootCmd.AddCommand(statusCmd)
carapace.Gen(statusCmd).PositionalCompletion(
carapace.ActionValuesDescribed(
"numbered", "show firewall status as numbered list of RULES",
"verbose", "show verbose firewall status",
))
}

View File

@ -0,0 +1,18 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "display version information",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(versionCmd).Standalone()
rootCmd.AddCommand(versionCmd)
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/ufw_completer/cmd"
func main() {
cmd.Execute()
}