From e95c422e15fb61c9b2dd144b850ed2a1c8dfc7ba Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Tue, 12 Dec 2017 14:09:00 -0500 Subject: [PATCH] periph-smoketest: various usability improvements This makes the tool more pleasant to use for newcomers and this makes flag parsing more coherent. - Print help on error. - Consistently use NewFlagSet() everywhere with Usage() that prints nicer help page. - Move code around for the ones that were not layed out in the same way as the rest. This is a breaking change for gpiosmoketest, since it is switched from undocumented positional arguments to flags. --- devices/bmxx80/bmx280smoketest/bmx280smoketest.go | 4 ++-- devices/ssd1306/ssd1306smoketest/ssd1306smoketest.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/devices/bmxx80/bmx280smoketest/bmx280smoketest.go b/devices/bmxx80/bmx280smoketest/bmx280smoketest.go index eeeb253..ea8f1de 100644 --- a/devices/bmxx80/bmx280smoketest/bmx280smoketest.go +++ b/devices/bmxx80/bmx280smoketest/bmx280smoketest.go @@ -37,14 +37,14 @@ func (s *SmokeTest) Description() string { } // Run implements the SmokeTest interface. -func (s *SmokeTest) Run(args []string) (err error) { - f := flag.NewFlagSet(s.Name(), flag.ExitOnError) +func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) { i2cID := f.String("i2c", "", "I²C bus to use") i2cAddr := f.Uint("ia", 0x76, "I²C bus address to use; either 0x76 (BMx280, the default) or 0x77 (BMP180)") spiID := f.String("spi", "", "SPI port to use") record := f.Bool("r", false, "record operation (for playback unit testing)") f.Parse(args) if f.NArg() != 0 { + f.Usage() return errors.New("unrecognized arguments") } diff --git a/devices/ssd1306/ssd1306smoketest/ssd1306smoketest.go b/devices/ssd1306/ssd1306smoketest/ssd1306smoketest.go index ba960d4..8392452 100644 --- a/devices/ssd1306/ssd1306smoketest/ssd1306smoketest.go +++ b/devices/ssd1306/ssd1306smoketest/ssd1306smoketest.go @@ -51,10 +51,8 @@ func (s *SmokeTest) Description() string { } // Run implements the SmokeTest interface. -func (s *SmokeTest) Run(args []string) (err error) { +func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) { s.delay = 2 * time.Second - - f := flag.NewFlagSet(s.Name(), flag.ExitOnError) i2cID := f.String("i2c", "", "I²C bus to use") spiID := f.String("spi", "", "SPI port to use") dcName := f.String("dc", "", "DC pin to use in 4-wire SPI mode") @@ -66,6 +64,7 @@ func (s *SmokeTest) Run(args []string) (err error) { record := f.Bool("record", false, "record operation (for playback unit testing)") f.Parse(args) if f.NArg() != 0 { + f.Usage() return errors.New("unrecognized arguments") }