Skip to content

Commit 4457449

Browse files
committed
Add -v/--version command flag
1 parent e2459cb commit 4457449

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

args.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// This file is part of serial-discovery.
3+
//
4+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
5+
//
6+
// This software is released under the GNU General Public License version 3,
7+
// which covers the main part of arduino-cli.
8+
// The terms of this license can be found at:
9+
// https://www.gnu.org/licenses/gpl-3.0.en.html
10+
//
11+
// You can be released from the requirements of the above licenses by purchasing
12+
// a commercial license. Buying such a license is mandatory if you want to modify or
13+
// otherwise use the software for commercial activities involving the Arduino
14+
// software without disclosing the source code of your own applications. To purchase
15+
// a commercial license, send an email to [email protected].
16+
//
17+
18+
package main
19+
20+
import (
21+
"fmt"
22+
"os"
23+
)
24+
25+
var args struct {
26+
showVersion bool
27+
}
28+
29+
func parseArgs() {
30+
for _, arg := range os.Args[1:] {
31+
if arg == "" {
32+
continue
33+
}
34+
if arg == "-v" || arg == "--version" {
35+
args.showVersion = true
36+
continue
37+
}
38+
fmt.Fprintf(os.Stderr, "invalid argument: %s\n", arg)
39+
os.Exit(1)
40+
}
41+
}

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// This file is part of serial-discovery.
33
//
4-
// Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
4+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
55
//
66
// This software is released under the GNU General Public License version 3,
77
// which covers the main part of arduino-cli.
@@ -26,10 +26,17 @@ import (
2626
"sync"
2727

2828
"github.com/arduino/go-properties-orderedmap"
29+
"github.com/arduino/serial-discovery/version"
2930
"go.bug.st/serial/enumerator"
3031
)
3132

3233
func main() {
34+
parseArgs()
35+
if args.showVersion {
36+
fmt.Printf("serial-discovery %s (build timestamp: %s)\n", version.Tag, version.Timestamp)
37+
return
38+
}
39+
3340
syncStarted := false
3441
var syncCloseChan chan<- bool
3542

version/version.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// This file is part of serial-discovery.
3+
//
4+
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
5+
//
6+
// This software is released under the GNU General Public License version 3,
7+
// which covers the main part of arduino-cli.
8+
// The terms of this license can be found at:
9+
// https://www.gnu.org/licenses/gpl-3.0.en.html
10+
//
11+
// You can be released from the requirements of the above licenses by purchasing
12+
// a commercial license. Buying such a license is mandatory if you want to modify or
13+
// otherwise use the software for commercial activities involving the Arduino
14+
// software without disclosing the source code of your own applications. To purchase
15+
// a commercial license, send an email to [email protected].
16+
//
17+
18+
package version
19+
20+
// Tag is the current git tag
21+
var Tag = "snapshot"
22+
23+
// Timestamp is the current timestamp
24+
var Timestamp = "unknown"

0 commit comments

Comments
 (0)