Skip to content

Commit e1583fc

Browse files
committed
Vendored go-configmap library and made it internal
1 parent d136b92 commit e1583fc

File tree

16 files changed

+248
-154
lines changed

16 files changed

+248
-154
lines changed

Diff for: go-configmap/go.mod

-13
This file was deleted.

Diff for: go-configmap/go.sum

-10
This file was deleted.

Diff for: go-configmap/json.go

-37
This file was deleted.

Diff for: go-configmap/json_test.go

-33
This file was deleted.

Diff for: go-configmap/yaml.go

-23
This file was deleted.

Diff for: go-configmap/yaml_test.go

-33
This file was deleted.

Diff for: go.mod

-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ go 1.21
55
// We must use this fork until https://github.com/mailru/easyjson/pull/372 is merged
66
replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1
77

8-
replace github.com/arduino/go-configmap => ./go-configmap
9-
108
require (
119
github.com/ProtonMail/go-crypto v1.1.0-alpha.0
12-
github.com/arduino/go-configmap v0.0.1
1310
github.com/arduino/go-paths-helper v1.12.0
1411
github.com/arduino/go-properties-orderedmap v1.8.0
1512
github.com/arduino/go-serial-utils v0.1.2

Diff for: internal/cli/configuration/configuration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"runtime"
2222

2323
"github.com/arduino/arduino-cli/internal/cli/feedback"
24+
"github.com/arduino/arduino-cli/internal/go-configmap"
2425
"github.com/arduino/arduino-cli/internal/i18n"
25-
"github.com/arduino/go-configmap"
2626
"github.com/arduino/go-win32-utils"
2727
)
2828

Diff for: go-configmap/cli.go renamed to internal/go-configmap/cli.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
116
package configmap
217

318
import (

Diff for: go-configmap/configuration.go renamed to internal/go-configmap/configuration.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
116
package configmap
217

318
import (

Diff for: go-configmap/configuration_test.go renamed to internal/go-configmap/configuration_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
116
package configmap_test
217

318
import (
419
"encoding/json"
520
"fmt"
621
"testing"
722

8-
"github.com/arduino/go-configmap"
23+
"github.com/arduino/arduino-cli/internal/go-configmap"
924
"github.com/stretchr/testify/require"
1025
"gopkg.in/yaml.v3"
1126
)

Diff for: internal/go-configmap/json.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package configmap
17+
18+
import "encoding/json"
19+
20+
func (c Map) MarshalJSON() ([]byte, error) {
21+
return json.Marshal(c.values)
22+
}
23+
24+
func (c *Map) UnmarshalJSON(data []byte) error {
25+
in := map[string]any{}
26+
if err := json.Unmarshal(data, &in); err != nil {
27+
return err
28+
}
29+
30+
c.values = map[string]any{}
31+
for k, v := range flattenMap(in) {
32+
if err := c.Set(k, v); err != nil {
33+
return err
34+
}
35+
}
36+
return nil
37+
}
38+
39+
func flattenMap(in map[string]any) map[string]any {
40+
out := map[string]any{}
41+
for k, v := range in {
42+
switch v := v.(type) {
43+
case map[string]any:
44+
for kk, vv := range flattenMap(v) {
45+
out[k+"."+kk] = vv
46+
}
47+
default:
48+
out[k] = v
49+
}
50+
}
51+
return out
52+
}

Diff for: internal/go-configmap/json_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package configmap_test
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/internal/go-configmap"
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
func TestJson(t *testing.T) {
28+
c := configmap.New()
29+
c.Set("foo", "bar")
30+
c.Set("fooz.bar", "baz")
31+
c.Set("answer", 42)
32+
require.Equal(t, "bar", c.Get("foo"))
33+
require.Equal(t, "baz", c.Get("fooz.bar"))
34+
require.Equal(t, 42, c.Get("answer"))
35+
36+
j1, err := json.Marshal(c)
37+
require.NoError(t, err)
38+
fmt.Println(string(j1))
39+
40+
d := configmap.New()
41+
err = json.Unmarshal(j1, d)
42+
require.NoError(t, err)
43+
require.Equal(t, "baz", d.Get("fooz.bar"))
44+
45+
j2, err := json.Marshal(d)
46+
require.NoError(t, err)
47+
require.Equal(t, string(j1), string(j2))
48+
}

Diff for: go-configmap/types.go renamed to internal/go-configmap/types.go

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
116
package configmap
217

318
import (

0 commit comments

Comments
 (0)