Skip to content

Commit 66fc6aa

Browse files
Add logging cli flag (#10)
1 parent 6e9ef67 commit 66fc6aa

File tree

9 files changed

+352
-2
lines changed

9 files changed

+352
-2
lines changed

.licensed.yml

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ sources:
55
reviewed:
66
go:
77
- github.com/arduino/go-paths-helper
8+
- golang.org/x/exp/constraints
9+
- golang.org/x/exp/slices
10+
- golang.org/x/exp/slog
11+
- golang.org/x/exp/slog/internal
12+
- golang.org/x/exp/slog/internal/buffer
813

914
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies/AGPL-3.0/.licensed.yml
1015
allowed:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: golang.org/x/exp/constraints
3+
version: v0.0.0-20230711153332-06a737ee72cb
4+
type: go
5+
summary: Package constraints defines a set of useful constraints to be used with type
6+
parameters.
7+
homepage: https://pkg.go.dev/golang.org/x/exp/constraints
8+
license: other
9+
licenses:
10+
- sources: [email protected]/LICENSE
11+
text: |
12+
Copyright (c) 2009 The Go Authors. All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are
16+
met:
17+
18+
* Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
* Redistributions in binary form must reproduce the above
21+
copyright notice, this list of conditions and the following disclaimer
22+
in the documentation and/or other materials provided with the
23+
distribution.
24+
* Neither the name of Google Inc. nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
- sources: [email protected]/PATENTS
40+
text: |
41+
Additional IP Rights Grant (Patents)
42+
43+
"This implementation" means the copyrightable works distributed by
44+
Google as part of the Go project.
45+
46+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
47+
no-charge, royalty-free, irrevocable (except as stated in this section)
48+
patent license to make, have made, use, offer to sell, sell, import,
49+
transfer and otherwise run, modify and propagate the contents of this
50+
implementation of Go, where such license applies only to those patent
51+
claims, both currently owned or controlled by Google and acquired in
52+
the future, licensable by Google that are necessarily infringed by this
53+
implementation of Go. This grant does not include claims that would be
54+
infringed only as a consequence of further modification of this
55+
implementation. If you or your agent or exclusive licensee institute or
56+
order or agree to the institution of patent litigation against any
57+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
58+
that this implementation of Go or any code incorporated within this
59+
implementation of Go constitutes direct or contributory patent
60+
infringement, or inducement of patent infringement, then any patent
61+
rights granted to you under this License for this implementation of Go
62+
shall terminate as of the date such litigation is filed.
63+
notices: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: golang.org/x/exp/slices
3+
version: v0.0.0-20230711153332-06a737ee72cb
4+
type: go
5+
summary: Package slices defines various functions useful with slices of any type.
6+
homepage: https://pkg.go.dev/golang.org/x/exp/slices
7+
license: other
8+
licenses:
9+
- sources: [email protected]/LICENSE
10+
text: |
11+
Copyright (c) 2009 The Go Authors. All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
* Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
* Redistributions in binary form must reproduce the above
20+
copyright notice, this list of conditions and the following disclaimer
21+
in the documentation and/or other materials provided with the
22+
distribution.
23+
* Neither the name of Google Inc. nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: [email protected]/PATENTS
39+
text: |
40+
Additional IP Rights Grant (Patents)
41+
42+
"This implementation" means the copyrightable works distributed by
43+
Google as part of the Go project.
44+
45+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
46+
no-charge, royalty-free, irrevocable (except as stated in this section)
47+
patent license to make, have made, use, offer to sell, sell, import,
48+
transfer and otherwise run, modify and propagate the contents of this
49+
implementation of Go, where such license applies only to those patent
50+
claims, both currently owned or controlled by Google and acquired in
51+
the future, licensable by Google that are necessarily infringed by this
52+
implementation of Go. This grant does not include claims that would be
53+
infringed only as a consequence of further modification of this
54+
implementation. If you or your agent or exclusive licensee institute or
55+
order or agree to the institution of patent litigation against any
56+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
57+
that this implementation of Go or any code incorporated within this
58+
implementation of Go constitutes direct or contributory patent
59+
infringement, or inducement of patent infringement, then any patent
60+
rights granted to you under this License for this implementation of Go
61+
shall terminate as of the date such litigation is filed.
62+
notices: []
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: golang.org/x/exp/slog
3+
version: v0.0.0-20230711153332-06a737ee72cb
4+
type: go
5+
summary: Package slog provides structured logging, in which log records include a
6+
message, a severity level, and various other attributes expressed as key-value pairs.
7+
homepage: https://pkg.go.dev/golang.org/x/exp/slog
8+
license: other
9+
licenses:
10+
- sources: [email protected]/LICENSE
11+
text: |
12+
Copyright (c) 2009 The Go Authors. All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are
16+
met:
17+
18+
* Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
* Redistributions in binary form must reproduce the above
21+
copyright notice, this list of conditions and the following disclaimer
22+
in the documentation and/or other materials provided with the
23+
distribution.
24+
* Neither the name of Google Inc. nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
- sources: [email protected]/PATENTS
40+
text: |
41+
Additional IP Rights Grant (Patents)
42+
43+
"This implementation" means the copyrightable works distributed by
44+
Google as part of the Go project.
45+
46+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
47+
no-charge, royalty-free, irrevocable (except as stated in this section)
48+
patent license to make, have made, use, offer to sell, sell, import,
49+
transfer and otherwise run, modify and propagate the contents of this
50+
implementation of Go, where such license applies only to those patent
51+
claims, both currently owned or controlled by Google and acquired in
52+
the future, licensable by Google that are necessarily infringed by this
53+
implementation of Go. This grant does not include claims that would be
54+
infringed only as a consequence of further modification of this
55+
implementation. If you or your agent or exclusive licensee institute or
56+
order or agree to the institution of patent litigation against any
57+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
58+
that this implementation of Go or any code incorporated within this
59+
implementation of Go constitutes direct or contributory patent
60+
infringement, or inducement of patent infringement, then any patent
61+
rights granted to you under this License for this implementation of Go
62+
shall terminate as of the date such litigation is filed.
63+
notices: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: golang.org/x/exp/slog/internal
3+
version: v0.0.0-20230711153332-06a737ee72cb
4+
type: go
5+
summary:
6+
homepage: https://pkg.go.dev/golang.org/x/exp/slog/internal
7+
license: other
8+
licenses:
9+
- sources: [email protected]/LICENSE
10+
text: |
11+
Copyright (c) 2009 The Go Authors. All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
* Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
* Redistributions in binary form must reproduce the above
20+
copyright notice, this list of conditions and the following disclaimer
21+
in the documentation and/or other materials provided with the
22+
distribution.
23+
* Neither the name of Google Inc. nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: [email protected]/PATENTS
39+
text: |
40+
Additional IP Rights Grant (Patents)
41+
42+
"This implementation" means the copyrightable works distributed by
43+
Google as part of the Go project.
44+
45+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
46+
no-charge, royalty-free, irrevocable (except as stated in this section)
47+
patent license to make, have made, use, offer to sell, sell, import,
48+
transfer and otherwise run, modify and propagate the contents of this
49+
implementation of Go, where such license applies only to those patent
50+
claims, both currently owned or controlled by Google and acquired in
51+
the future, licensable by Google that are necessarily infringed by this
52+
implementation of Go. This grant does not include claims that would be
53+
infringed only as a consequence of further modification of this
54+
implementation. If you or your agent or exclusive licensee institute or
55+
order or agree to the institution of patent litigation against any
56+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
57+
that this implementation of Go or any code incorporated within this
58+
implementation of Go constitutes direct or contributory patent
59+
infringement, or inducement of patent infringement, then any patent
60+
rights granted to you under this License for this implementation of Go
61+
shall terminate as of the date such litigation is filed.
62+
notices: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: golang.org/x/exp/slog/internal/buffer
3+
version: v0.0.0-20230711153332-06a737ee72cb
4+
type: go
5+
summary: Package buffer provides a pool-allocated byte buffer.
6+
homepage: https://pkg.go.dev/golang.org/x/exp/slog/internal/buffer
7+
license: other
8+
licenses:
9+
- sources: [email protected]/LICENSE
10+
text: |
11+
Copyright (c) 2009 The Go Authors. All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
* Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
* Redistributions in binary form must reproduce the above
20+
copyright notice, this list of conditions and the following disclaimer
21+
in the documentation and/or other materials provided with the
22+
distribution.
23+
* Neither the name of Google Inc. nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: [email protected]/PATENTS
39+
text: |
40+
Additional IP Rights Grant (Patents)
41+
42+
"This implementation" means the copyrightable works distributed by
43+
Google as part of the Go project.
44+
45+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
46+
no-charge, royalty-free, irrevocable (except as stated in this section)
47+
patent license to make, have made, use, offer to sell, sell, import,
48+
transfer and otherwise run, modify and propagate the contents of this
49+
implementation of Go, where such license applies only to those patent
50+
claims, both currently owned or controlled by Google and acquired in
51+
the future, licensable by Google that are necessarily infringed by this
52+
implementation of Go. This grant does not include claims that would be
53+
infringed only as a consequence of further modification of this
54+
implementation. If you or your agent or exclusive licensee institute or
55+
order or agree to the institution of patent litigation against any
56+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
57+
that this implementation of Go or any code incorporated within this
58+
implementation of Go constitutes direct or contributory patent
59+
infringement, or inducement of patent infringement, then any patent
60+
rights granted to you under this License for this implementation of Go
61+
shall terminate as of the date such litigation is filed.
62+
notices: []

cli.go

+32-2
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ package helper
1818

1919
import (
2020
"fmt"
21+
"io"
2122
"os"
2223
"path/filepath"
2324

2425
"github.com/arduino/go-paths-helper"
2526
"github.com/spf13/cobra"
27+
"golang.org/x/exp/slog"
2628
"gopkg.in/yaml.v3"
2729
)
2830

2931
// RunPlugin runs the given plugin
3032
func RunPlugin(plugin Plugin) {
3133
info := plugin.GetPluginInfo()
3234

33-
var portAddress string
34-
var fqbn string
35+
var (
36+
fqbn string
37+
logLevel string
38+
verbose bool
39+
portAddress string
40+
)
3541

3642
firmwareFlashCmd := &cobra.Command{
3743
Use: "flash",
@@ -117,6 +123,28 @@ func RunPlugin(plugin Plugin) {
117123
cli := &cobra.Command{
118124
Use: appName,
119125
Short: info.Name + " - This is an Arduino Firmware Uploader plugin.",
126+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
127+
t, found := map[string]slog.Level{
128+
"trace": slog.LevelDebug,
129+
"debug": slog.LevelDebug,
130+
"info": slog.LevelInfo,
131+
"warn": slog.LevelWarn,
132+
"error": slog.LevelError,
133+
"fatal": slog.LevelError,
134+
"panic": slog.LevelError,
135+
}[logLevel]
136+
if !found {
137+
t = slog.LevelError
138+
}
139+
140+
var w io.Writer
141+
if !verbose {
142+
w = io.Discard
143+
} else {
144+
w = os.Stdout
145+
}
146+
slog.SetDefault(slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{Level: t})))
147+
},
120148
}
121149
cli.AddCommand(firmwareCmd)
122150
cli.AddCommand(certCmd)
@@ -125,6 +153,8 @@ func RunPlugin(plugin Plugin) {
125153
// The fqbn is an optional flag that can be used by the plugin to do specific operations with a board.
126154
// With this input we can support a family of boards and not only a single one per plugin
127155
cli.PersistentFlags().StringVarP(&fqbn, "fqbn", "b", "", "Fully qualified board name")
156+
cli.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic")
157+
cli.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Print the logs on the standard output.")
128158

129159
if err := cli.Execute(); err != nil {
130160
fatal(err.Error(), 1)

0 commit comments

Comments
 (0)