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: var-declaration
|
||||
- name: blank-imports
|
||||
- name: range
|
||||
|
||||
# Disabled rules (can be enabled if needed)
|
||||
# - name: line-length-limit
|
||||
@ -82,17 +81,6 @@ linters:
|
||||
- G104 # Duplicated errcheck checks
|
||||
- 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:
|
||||
# Enable specific formatters
|
||||
@ -118,8 +106,5 @@ formatters:
|
||||
extra-rules: true # Enable additional formatting rules
|
||||
|
||||
issues:
|
||||
# Limit the number of same issues reported to avoid spam
|
||||
max-same-issues: 50
|
||||
|
||||
# Limit the number of issues per linter to keep output manageable
|
||||
max-issues-per-linter: 100
|
||||
max-same-issues: 0
|
||||
max-issues-per-linter: 0
|
||||
|
||||
@ -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() {
|
||||
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
|
||||
|
||||
// VBAN specific flags
|
||||
@ -82,7 +66,7 @@ func run() (func(), error) {
|
||||
|
||||
configDir, err := os.UserConfigDir()
|
||||
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")
|
||||
|
||||
@ -114,7 +98,7 @@ func run() (func(), error) {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs, "vbantxt [flags] <vban commands>"))
|
||||
os.Exit(0)
|
||||
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 {
|
||||
@ -124,7 +108,7 @@ func run() (func(), error) {
|
||||
|
||||
level, err := log.ParseLevel(flags.Loglevel)
|
||||
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)
|
||||
|
||||
@ -132,18 +116,16 @@ func run() (func(), error) {
|
||||
|
||||
client, closer, err := createClient(&flags)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create VBAN client: %w", err)
|
||||
exitOnError(err)
|
||||
}
|
||||
defer closer()
|
||||
|
||||
commands := fs.GetArgs()
|
||||
if len(commands) == 0 {
|
||||
return closer, errors.New(
|
||||
"no VBAN commands provided; please provide at least one command as an argument",
|
||||
)
|
||||
exitOnError(errors.New("no VBAN commands provided"))
|
||||
}
|
||||
|
||||
sendCommands(client, commands)
|
||||
return closer, nil
|
||||
}
|
||||
|
||||
// versionFromBuild retrieves the version information from the build metadata.
|
||||
@ -151,7 +133,7 @@ func versionFromBuild() string {
|
||||
if version == "" {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "(unable to read build info)"
|
||||
exitOnError(errors.New("failed to read build info"))
|
||||
}
|
||||
version = strings.Split(info.Main.Version, "-")[0]
|
||||
}
|
||||
@ -180,11 +162,13 @@ func createClient(flags *Flags) (*vbantxt.VbanTxt, func(), error) {
|
||||
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) {
|
||||
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)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user