Skip to content

Commit

Permalink
skip checks for stdout/stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi committed Jan 18, 2020
1 parent 84c50ad commit 751d5ac
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,57 +66,57 @@ func getParams() (source iface.ReadSeekerCloser, displays []reader.ByteFormatter
remainingArgs, err := opt.Parse(os.Args[1:])

if opt.Called("help") {
fmt.Fprintf(os.Stdout, `heksa - hex file dumper %v - (%v)`+"\n", VERSION, BUILDDATE)
fmt.Fprintf(os.Stdout, `(c) %v 2019- [ %v ]`+"\n", AUTHOR, HOMEPAGE)
fmt.Fprintln(os.Stdout, opt.Help())
fmt.Fprintln(os.Stdout, `NOTES:`)
fmt.Fprintln(os.Stdout, ` - You can use prefixes for seek and limit. 0x = hex, 0b = binary, 0o = octal`)
fmt.Fprintln(os.Stdout, ` - Use 'no' or '' for offset formatter for disabling offset output`)
fmt.Fprintln(os.Stdout, ` - Use '--seek \-[prefix]1000' for seeking to end of file`)
fmt.Fprintln(os.Stdout, ` - Offset and seek parameters supports units (KB, KiB, MB, MiB, GB, GiB, TB, TiB)`)
fmt.Fprintln(os.Stdout)
fmt.Fprintln(os.Stdout, `EXAMPLES:`)
fmt.Fprintln(os.Stdout, ` heksa -f hex,asc,bit foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -o hex,per -f hex,asc foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -o hex -f hex,asc,bit foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -o no -f bit foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -l 0x1024 foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -s 0b1010 foo.dat`)
fmt.Fprintln(os.Stdout, ` heksa -s 4321KiB foo.dat`)
_, _ = fmt.Fprintf(os.Stdout, `heksa - hex file dumper %v - (%v)`+"\n", VERSION, BUILDDATE)
_, _ = fmt.Fprintf(os.Stdout, `(c) %v 2019- [ %v ]`+"\n", AUTHOR, HOMEPAGE)
_, _ = fmt.Fprintln(os.Stdout, opt.Help())
_, _ = fmt.Fprintln(os.Stdout, `NOTES:`)
_, _ = fmt.Fprintln(os.Stdout, ` - You can use prefixes for seek and limit. 0x = hex, 0b = binary, 0o = octal`)
_, _ = fmt.Fprintln(os.Stdout, ` - Use 'no' or '' for offset formatter for disabling offset output`)
_, _ = fmt.Fprintln(os.Stdout, ` - Use '--seek \-[prefix]1000' for seeking to end of file`)
_, _ = fmt.Fprintln(os.Stdout, ` - Offset and seek parameters supports units (KB, KiB, MB, MiB, GB, GiB, TB, TiB)`)
_, _ = fmt.Fprintln(os.Stdout)
_, _ = fmt.Fprintln(os.Stdout, `EXAMPLES:`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -f hex,asc,bit foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -o hex,per -f hex,asc foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -o hex -f hex,asc,bit foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -o no -f bit foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -l 0x1024 foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -s 0b1010 foo.dat`)
_, _ = fmt.Fprintln(os.Stdout, ` heksa -s 4321KiB foo.dat`)
os.Exit(0)
} else if opt.Called("version") {
fmt.Fprintf(os.Stdout, `%v build %v on %v`+"\n", VERSION, BUILD, BUILDDATE)
_, _ = fmt.Fprintf(os.Stdout, `%v build %v on %v`+"\n", VERSION, BUILD, BUILDDATE)
os.Exit(0)
}

if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
fmt.Fprintln(os.Stderr, opt.Help(getoptions.HelpSynopsis))
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
_, _ = fmt.Fprintln(os.Stderr, opt.Help(getoptions.HelpSynopsis))
os.Exit(1)
}

limitTmp, err := units.Parse(*argLimit)
if err != nil {
fmt.Fprintf(os.Stderr, `error parsing limit: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error parsing limit: %v`, err)
os.Exit(1)
}
limit = uint64(limitTmp)

startOffset, err := units.Parse(strings.Replace(*argSeek, `\`, ``, -1))
if err != nil {
fmt.Fprintf(os.Stderr, `error parsing seek: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error parsing seek: %v`, err)
os.Exit(1)
}

offsetViewer, err = reader.GetOffsetFormatters(strings.Split(*argOffset, `,`))
if err != nil {
fmt.Fprintf(os.Stderr, `error getting offset formatter: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error getting offset formatter: %v`, err)
os.Exit(1)
}

displays, err = reader.GetViewers(strings.Split(*argFormat, `,`))
if err != nil {
fmt.Fprintf(os.Stderr, `error getting formatter: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error getting formatter: %v`, err)
os.Exit(1)
}

Expand All @@ -130,26 +130,26 @@ func getParams() (source iface.ReadSeekerCloser, displays []reader.ByteFormatter
} else {
// Read file
if len(remainingArgs) != 1 {
fmt.Fprintln(os.Stderr, `error: no file given as argument, see --help`)
_, _ = fmt.Fprintln(os.Stderr, `error: no file given as argument, see --help`)
os.Exit(1)
}

fpath := remainingArgs[0]

fhandle, err := os.Open(fpath)
if err != nil {
fmt.Fprintf(os.Stderr, `error opening file: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error opening file: %v`, err)
os.Exit(1)
}

fi, err := fhandle.Stat()
if err != nil {
fmt.Fprintf(os.Stderr, `error stat'ing file: %v`, err)
_, _ = fmt.Fprintf(os.Stderr, `error stat'ing file: %v`, err)
os.Exit(1)
}

if fi.IsDir() {
fmt.Fprintf(os.Stderr, `error: %v is directory`, fpath)
_, _ = fmt.Fprintf(os.Stderr, `error: %v is directory`, fpath)
os.Exit(1)
}

Expand All @@ -161,7 +161,7 @@ func getParams() (source iface.ReadSeekerCloser, displays []reader.ByteFormatter
}

if err != nil {
fmt.Fprintf(os.Stderr, `couldn't seek to %v: %v`, startOffset, err)
_, _ = fmt.Fprintf(os.Stderr, `couldn't seek to %v: %v`, startOffset, err)
os.Exit(1)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ func main() {
break
}

fmt.Fprintln(os.Stderr, fmt.Sprintf(`error while reading file: %v`, err))
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf(`error while reading file: %v`, err))
os.Exit(1)
}

Expand All @@ -205,7 +205,7 @@ func main() {
}
isEven = !isEven

fmt.Printf(`%s%s%s`+"\n", color, s, clear)
_, _ = fmt.Printf(`%s%s%s`+"\n", color, s, clear)

if limit > 0 && r.ReadBytes >= limit {
// Limit is set and found
Expand Down

0 comments on commit 751d5ac

Please sign in to comment.