mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-03-03 16:49:15 +00:00
Compare commits
No commits in common. "5d9924ff58acde03d5554120cac428248ccc61a5" and "87ea26ab03e06645049687a566636fa3b73bef7e" have entirely different histories.
5d9924ff58
...
87ea26ab03
@ -67,7 +67,6 @@ linters:
|
|||||||
- name: unused-parameter
|
- name: unused-parameter
|
||||||
- name: var-declaration
|
- name: var-declaration
|
||||||
- name: blank-imports
|
- name: blank-imports
|
||||||
- name: range
|
|
||||||
|
|
||||||
# Disabled rules (can be enabled if needed)
|
# Disabled rules (can be enabled if needed)
|
||||||
# - name: line-length-limit
|
# - name: line-length-limit
|
||||||
@ -82,17 +81,6 @@ linters:
|
|||||||
- G104 # Duplicated errcheck checks
|
- G104 # Duplicated errcheck checks
|
||||||
- G115 # integer overflow conversion int -> uint32
|
- G115 # integer overflow conversion int -> uint32
|
||||||
|
|
||||||
exclusions:
|
|
||||||
warn-unused: false
|
|
||||||
rules:
|
|
||||||
# Exclude some linters from running on tests files.
|
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- gocyclo
|
|
||||||
- errcheck
|
|
||||||
- dupl
|
|
||||||
- gosec
|
|
||||||
|
|
||||||
# Formatters configuration
|
# Formatters configuration
|
||||||
formatters:
|
formatters:
|
||||||
# Enable specific formatters
|
# Enable specific formatters
|
||||||
@ -118,8 +106,5 @@ formatters:
|
|||||||
extra-rules: true # Enable additional formatting rules
|
extra-rules: true # Enable additional formatting rules
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Limit the number of same issues reported to avoid spam
|
max-same-issues: 0
|
||||||
max-same-issues: 50
|
max-issues-per-linter: 0
|
||||||
|
|
||||||
# Limit the number of issues per linter to keep output manageable
|
|
||||||
max-issues-per-linter: 100
|
|
||||||
|
|||||||
@ -47,28 +47,12 @@ func (f *Flags) String() string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exitOnError(err error) {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var exitCode int
|
|
||||||
|
|
||||||
// Defer exit with the final exit code
|
|
||||||
defer func() {
|
|
||||||
if exitCode != 0 {
|
|
||||||
os.Exit(exitCode)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
closer, err := run()
|
|
||||||
if closer != nil {
|
|
||||||
defer closer()
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
exitCode = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run contains the main application logic and returns a closer function and any error.
|
|
||||||
func run() (func(), error) {
|
|
||||||
var flags Flags
|
var flags Flags
|
||||||
|
|
||||||
// VBAN specific flags
|
// VBAN specific flags
|
||||||
@ -82,7 +66,7 @@ func run() (func(), error) {
|
|||||||
|
|
||||||
configDir, err := os.UserConfigDir()
|
configDir, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get user config directory: %w", err)
|
exitOnError(fmt.Errorf("failed to get user config directory: %w", err))
|
||||||
}
|
}
|
||||||
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
||||||
|
|
||||||
@ -114,7 +98,7 @@ func run() (func(), error) {
|
|||||||
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs, "vbantxt [flags] <vban commands>"))
|
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs, "vbantxt [flags] <vban commands>"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, fmt.Errorf("failed to parse flags: %w", err)
|
exitOnError(fmt.Errorf("failed to parse flags: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Version {
|
if flags.Version {
|
||||||
@ -124,7 +108,7 @@ func run() (func(), error) {
|
|||||||
|
|
||||||
level, err := log.ParseLevel(flags.Loglevel)
|
level, err := log.ParseLevel(flags.Loglevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid log level %q", flags.Loglevel)
|
exitOnError(fmt.Errorf("invalid log level: %s", flags.Loglevel))
|
||||||
}
|
}
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
|
||||||
@ -132,18 +116,16 @@ func run() (func(), error) {
|
|||||||
|
|
||||||
client, closer, err := createClient(&flags)
|
client, closer, err := createClient(&flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create VBAN client: %w", err)
|
exitOnError(err)
|
||||||
}
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
commands := fs.GetArgs()
|
commands := fs.GetArgs()
|
||||||
if len(commands) == 0 {
|
if len(commands) == 0 {
|
||||||
return closer, errors.New(
|
exitOnError(errors.New("no VBAN commands provided"))
|
||||||
"no VBAN commands provided; please provide at least one command as an argument",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommands(client, commands)
|
sendCommands(client, commands)
|
||||||
return closer, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// versionFromBuild retrieves the version information from the build metadata.
|
// versionFromBuild retrieves the version information from the build metadata.
|
||||||
@ -151,7 +133,7 @@ func versionFromBuild() string {
|
|||||||
if version == "" {
|
if version == "" {
|
||||||
info, ok := debug.ReadBuildInfo()
|
info, ok := debug.ReadBuildInfo()
|
||||||
if !ok {
|
if !ok {
|
||||||
return "(unable to read build info)"
|
exitOnError(errors.New("failed to read build info"))
|
||||||
}
|
}
|
||||||
version = strings.Split(info.Main.Version, "-")[0]
|
version = strings.Split(info.Main.Version, "-")[0]
|
||||||
}
|
}
|
||||||
@ -180,11 +162,13 @@ func createClient(flags *Flags) (*vbantxt.VbanTxt, func(), error) {
|
|||||||
return client, closer, err
|
return client, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendCommands sends the provided VBAN commands using the client and logs any errors that occur.
|
// sendCommands sends a list of commands to the VBAN client.
|
||||||
func sendCommands(client *vbantxt.VbanTxt, commands []string) {
|
func sendCommands(client *vbantxt.VbanTxt, commands []string) {
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
if err := client.Send(cmd); err != nil {
|
err := client.Send(cmd)
|
||||||
|
if err != nil {
|
||||||
log.Errorf("Failed to send command '%s': %v", cmd, err)
|
log.Errorf("Failed to send command '%s': %v", cmd, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user