Debian Codegraph @

dummy-discovery/args/args.go

raw
1 // This file is part of dummy-discovery.
2 //
3 // SPDX-FileCopyrightText: Arduino s.r.l. and/or its affiliated companies
4 // SPDX-License-Identifier: GPL-3.0-or-later
5
6 // Package args contains arguments parsing subroutines for the dummy-discovery binary.
7 package args
8
9 import (
10 "fmt"
11 "os"
12 "time"
13 )
14
15 // Tag is the current git tag
16 var Tag = "snapshot"
17
18 // Timestamp is the current timestamp
19 var Timestamp = "unknown"
20
21 // Parse arguments passed by the user
22 func Parse() {
23 for _, arg := range os.Args[1:] {
24 if arg == "" {
25 continue
26 }
27 if arg == "-v" || arg == "--version" {
28 fmt.Printf("dummy-discovery %s (build timestamp: %s)\n", Tag, Timestamp)
29 os.Exit(0)
30 }
31 if arg == "-k" {
32 // Emulate crashing discovery
33 go func() {
34 time.Sleep(time.Millisecond * 500)
35 os.Exit(1)
36 }()
37 continue
38 }
39 fmt.Fprintf(os.Stderr, "invalid argument: %s\n", arg)
40 os.Exit(1)
41 }
42 }