refactor: clean up unused code, fix typos, improve docs (#7)

* refactor: clean up unused code, fix typos, improve docs

- Remove unused 'killed' const and 'unitTypes' var (staticcheck U1000)
- Replace regexp with strings.TrimSuffix+switch in isFailed for consistency
- Fix typo: 'programatically' -> 'programmatically'
- Fix typo: 'an an int' -> 'as an int' in README and helpers.go
- Add missing godoc comments on exported helper functions
- Bump minimum Go version from 1.18 to 1.21

* refactor: use unused constants instead of removing them

- Export unitTypes as UnitTypes and add HasValidUnitSuffix helper
- Use killed const (exit code 130) in execute() to detect SIGINT
- Update go.mod to go 1.26
This commit is contained in:
2026-02-23 00:01:59 -05:00
committed by GitHub
parent 14c9f0f70d
commit d38136c0dc
7 changed files with 39 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
package systemctl
import "strings"
type Options struct {
UserMode bool
}
@@ -12,7 +14,8 @@ type Unit struct {
Description string
}
var unitTypes = []string{
// UnitTypes contains all valid systemd unit type suffixes.
var UnitTypes = []string{
"automount",
"device",
"mount",
@@ -26,3 +29,14 @@ var unitTypes = []string{
"target",
"timer",
}
// HasValidUnitSuffix checks whether the given unit name ends with a valid
// systemd unit type suffix (e.g. ".service", ".timer").
func HasValidUnitSuffix(unit string) bool {
for _, t := range UnitTypes {
if strings.HasSuffix(unit, "."+t) {
return true
}
}
return false
}