Skip to content

Commit

Permalink
Merge pull request #155 from rsteube/document-actions
Browse files Browse the repository at this point in the history
added documentation to actions
  • Loading branch information
rsteube authored Oct 7, 2020
2 parents 6986461 + de58a03 commit 2d2267a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.60.2 h1:7i8mqModL63zqi8nQn8Q3+0zvSCZy1AxhBgthKfi4WU=
gopkg.in/ini.v1 v1.60.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
Expand Down
2 changes: 2 additions & 0 deletions pkg/actions/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/ini.v1"
)

// ActionRegions completes region names
func ActionRegions() carapace.Action {
return carapace.ActionValuesDescribed(
"af-south-1", "Africa (Cape Town)",
Expand All @@ -33,6 +34,7 @@ func ActionRegions() carapace.Action {
)
}

// ActionProfiles completes configuration profile names
func ActionProfiles() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
profiles := []string{}
Expand Down
1 change: 1 addition & 0 deletions pkg/actions/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/rsteube/carapace"
)

// ActionMounts completes file system mounts
func ActionMounts() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("mount").Output(); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/actions/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rsteube/carapace"
)

// ActionHosts completes known hosts
func ActionHosts() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
hosts := []string{}
Expand All @@ -30,6 +31,7 @@ func ActionHosts() carapace.Action {
})
}

// ActionNetInterfaces completes network interface names
func ActionNetInterfaces() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("ifconfig").Output(); err != nil {
Expand Down
24 changes: 19 additions & 5 deletions pkg/actions/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ import (
"io/ioutil"
"os"
"os/exec"
"strconv"
"strings"

ps "github.com/mitchellh/go-ps"
"github.com/rsteube/carapace"
)

// ActionEnvironmentVariables completes environment values
func ActionEnvironmentVariables() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
env := os.Environ()
vars := make([]string, len(env))
vars := make([]string, len(env)*2)
for index, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
vars[index] = pair[0]
vars[index*2] = pair[0]
if len(pair[1]) > 40 {
vars[(index*2)+1] = pair[1][:37] + "..."
} else {
vars[(index*2)+1] = pair[1]
}
}
return carapace.ActionValues(vars...)
return carapace.ActionValuesDescribed(vars...)
})
}

// ActionGroups completes system group names
func ActionGroups() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
groups := []string{}
Expand All @@ -41,6 +49,7 @@ func ActionGroups() carapace.Action {
})
}

// ActionKillSignals completes linux kill signals
func ActionKillSignals() carapace.Action {
return carapace.ActionValuesDescribed(
"ABRT", "Abnormal termination",
Expand Down Expand Up @@ -77,20 +86,22 @@ func ActionKillSignals() carapace.Action {
)
}

// ActionProcessExecutables completes executable names of current processes
func ActionProcessExecutables() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if processes, err := ps.Processes(); err != nil {
return carapace.ActionMessage(err.Error())
} else {
executables := make([]string, 0)
for _, process := range processes {
executables = append(executables, process.Executable())
executables = append(executables, process.Executable(), strconv.Itoa(process.Pid()))
}
return carapace.ActionValues(executables...)
return carapace.ActionValuesDescribed(executables...)
}
})
}

// ActionProcessStates completes linux process states
func ActionProcessStates() carapace.Action {
return carapace.ActionValuesDescribed(
"D", "uninterruptible sleep (usually IO)",
Expand All @@ -105,6 +116,7 @@ func ActionProcessStates() carapace.Action {
)
}

// ActionUsers completes system user names
func ActionUsers() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
users := []string{}
Expand All @@ -124,6 +136,7 @@ func ActionUsers() carapace.Action {
})
}

// ActionUserGroup completes system user:group separately
func ActionUserGroup() carapace.Action {
return carapace.ActionMultiParts(":", func(args []string, parts []string) carapace.Action {
switch len(parts) {
Expand All @@ -137,6 +150,7 @@ func ActionUserGroup() carapace.Action {
})
}

// ActionShells completes available terminal shells
func ActionShells() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("chsh", "--list-shells").Output(); err != nil {
Expand Down

0 comments on commit 2d2267a

Please sign in to comment.