Skip to content

Commit

Permalink
Minor refactoring, add gover managed versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
sabhiram committed Apr 5, 2018
1 parent ca398e3 commit 02d1b0f
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 56 deletions.
2 changes: 0 additions & 2 deletions cmd/wol/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,3 @@ func (a *Aliases) Close() error {

return a.db.Close()
}

////////////////////////////////////////////////////////////////////////////////
2 changes: 0 additions & 2 deletions cmd/wol/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,3 @@ func (suite *AliasDBTests) TestGetAlias() {
func TestRunAllSuites(t *testing.T) {
suite.Run(t, new(AliasDBTests))
}

////////////////////////////////////////////////////////////////////////////////
2 changes: 0 additions & 2 deletions cmd/wol/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,3 @@ func isValidCommand(s string) bool {
}
return false
}

////////////////////////////////////////////////////////////////////////////////
35 changes: 0 additions & 35 deletions cmd/wol/version.go

This file was deleted.

13 changes: 13 additions & 0 deletions cmd/wol/version_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

// WARNING: Auto generated version file. Do not edit this file by hand.
// WARNING: go get github.com/sabhiram/gover to manage this file.
// Version: 1.0.3

const (
Major = 1
Minor = 0
Patch = 3

Version = "1.0.3"
)
14 changes: 6 additions & 8 deletions cmd/wol/wol.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,24 @@ func main() {
parser := flags.NewParser(&Options, flags.Default & ^flags.HelpFlag)
args, err = parser.Parse()

exitCode := 0
ec := 0
switch {

// Parse Error, print usage
case err != nil:
exitCode = printUsageGetExitCode("", 1)
ec = printUsageGetExitCode("", 1)

// No arguments, or help requested, print usage
case len(os.Args) == 1 || Options.Help:
exitCode = printUsageGetExitCode("", 0)
ec = printUsageGetExitCode("", 0)

// "--version" requested
case Options.Version:
fmt.Printf("%s\n", Version)

// Make sure we are being asked to run a something
case len(args) == 0:
exitCode = printUsageGetExitCode("No command specified, see usage:\n", 1)
ec = printUsageGetExitCode("No command specified, see usage:\n", 1)

// All other cases go here
case true:
Expand All @@ -197,11 +197,9 @@ func main() {

if err != nil {
fmt.Printf("%s\n", err.Error())
exitCode = 1
ec = 1
}

}
os.Exit(exitCode)
os.Exit(ec)
}

////////////////////////////////////////////////////////////////////////////////
8 changes: 3 additions & 5 deletions magic_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ func SendMagicPacket(macAddr, bcastAddr, iface string) error {
defer connection.Close()

// Write the bytes of the MagicPacket to the connection
bytesWritten, err := connection.Write(buf.Bytes())
n, err := connection.Write(buf.Bytes())
if err != nil {
return err
} else if bytesWritten != 102 {
fmt.Printf("Warning: %d bytes written, %d expected!\n", bytesWritten, 102)
} else if n != 102 {
fmt.Printf("Warning: %d bytes written, %d expected!\n", n, 102)
}

return nil
}

////////////////////////////////////////////////////////////////////////////////
2 changes: 0 additions & 2 deletions magic_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,3 @@ func TestGetIpFromInterfaceNegative(t *testing.T) {
assert.NotNil(t, err)
}
}

////////////////////////////////////////////////////////////////////////////////

0 comments on commit 02d1b0f

Please sign in to comment.