diff --git a/.licenses/go/go.bug.st/f.dep.yml b/.licenses/go/go.bug.st/f.dep.yml new file mode 100644 index 00000000000..59ef92f95a3 --- /dev/null +++ b/.licenses/go/go.bug.st/f.dep.yml @@ -0,0 +1,45 @@ +--- +name: go.bug.st/f +version: v0.4.0 +type: go +summary: Package f is a golang library implementing some basic algorithms. +homepage: https://godoc.org/go.bug.st/f +license: bsd-3-clause +licenses: +- sources: LICENSE + text: |2+ + + Copyright (c) 2024, Cristian Maglie. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +notices: [] +... diff --git a/commands/service_board_list.go b/commands/service_board_list.go index daf7ca57a87..1d1bf7acff5 100644 --- a/commands/service_board_list.go +++ b/commands/service_board_list.go @@ -22,12 +22,12 @@ import ( "github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/commands/internal/instances" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/discovery/discoverymanager" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/arduino-cli/pkg/fqbn" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/sirupsen/logrus" + "go.bug.st/f" ) // BoardList returns a list of boards found by the loaded discoveries. diff --git a/commands/service_settings.go b/commands/service_settings.go index d38f4a95cfd..7a0f7f252ae 100644 --- a/commands/service_settings.go +++ b/commands/service_settings.go @@ -22,10 +22,10 @@ import ( "reflect" "github.com/arduino/arduino-cli/commands/cmderrors" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/cli/configuration" "github.com/arduino/arduino-cli/internal/go-configmap" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "go.bug.st/f" "google.golang.org/protobuf/proto" "gopkg.in/yaml.v3" ) diff --git a/internal/algorithms/slices.go b/internal/algorithms/slices.go deleted file mode 100644 index 90ea3d1984b..00000000000 --- a/internal/algorithms/slices.go +++ /dev/null @@ -1,87 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2023 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package f - -// Matcher is a function that tests if a given value match a certain criteria. -type Matcher[T any] func(T) bool - -// Reducer is a function that combines two values of the same type and return -// the combined value. -type Reducer[T any] func(T, T) T - -// Mapper is a function that converts a value of one type to another type. -type Mapper[T, U any] func(T) U - -// Filter takes a slice of type []T and a Matcher[T]. It returns a newly -// allocated slice containing only those elements of the input slice that -// satisfy the matcher. -func Filter[T any](values []T, matcher Matcher[T]) []T { - res := []T{} - for _, x := range values { - if matcher(x) { - res = append(res, x) - } - } - return res -} - -// Map applies the Mapper function to each element of the slice and returns -// a new slice with the results in the same order. -func Map[T, U any](values []T, mapper Mapper[T, U]) []U { - res := []U{} - for _, x := range values { - res = append(res, mapper(x)) - } - return res -} - -// Reduce applies the Reducer function to all elements of the input values -// and returns the result. -func Reduce[T any](values []T, reducer Reducer[T]) T { - var result T - for _, v := range values { - result = reducer(result, v) - } - return result -} - -// Equals return a Matcher that matches the given value -func Equals[T comparable](value T) Matcher[T] { - return func(x T) bool { - return x == value - } -} - -// NotEquals return a Matcher that does not match the given value -func NotEquals[T comparable](value T) Matcher[T] { - return func(x T) bool { - return x != value - } -} - -// Uniq return a copy of the input array with all duplicates removed -func Uniq[T comparable](in []T) []T { - have := map[T]bool{} - var out []T - for _, v := range in { - if have[v] { - continue - } - out = append(out, v) - have[v] = true - } - return out -} diff --git a/internal/algorithms/slices_test.go b/internal/algorithms/slices_test.go deleted file mode 100644 index 8ef58c660a9..00000000000 --- a/internal/algorithms/slices_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2023 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package f_test - -import ( - "strings" - "testing" - - f "github.com/arduino/arduino-cli/internal/algorithms" - "github.com/stretchr/testify/require" -) - -func TestFilter(t *testing.T) { - a := []string{"aaa", "bbb", "ccc"} - require.Equal(t, []string{"bbb", "ccc"}, f.Filter(a, func(x string) bool { return x > "b" })) - b := []int{5, 9, 15, 2, 4, -2} - require.Equal(t, []int{5, 9, 15}, f.Filter(b, func(x int) bool { return x > 4 })) -} - -func TestIsEmpty(t *testing.T) { - require.True(t, f.Equals(int(0))(0)) - require.False(t, f.Equals(int(1))(0)) - require.True(t, f.Equals("")("")) - require.False(t, f.Equals("abc")("")) - require.False(t, f.NotEquals(int(0))(0)) - require.True(t, f.NotEquals(int(1))(0)) - require.False(t, f.NotEquals("")("")) - require.True(t, f.NotEquals("abc")("")) -} - -func TestMap(t *testing.T) { - value := "hello, world , how are,you? " - parts := f.Map(strings.Split(value, ","), strings.TrimSpace) - - require.Equal(t, 4, len(parts)) - require.Equal(t, "hello", parts[0]) - require.Equal(t, "world", parts[1]) - require.Equal(t, "how are", parts[2]) - require.Equal(t, "you?", parts[3]) -} diff --git a/internal/arduino/builder/core.go b/internal/arduino/builder/core.go index f407ed60c41..f541eaeda41 100644 --- a/internal/arduino/builder/core.go +++ b/internal/arduino/builder/core.go @@ -22,12 +22,12 @@ import ( "os" "strings" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/builder/cpp" "github.com/arduino/arduino-cli/internal/arduino/builder/internal/utils" "github.com/arduino/arduino-cli/internal/buildcache" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/go-paths-helper" + "go.bug.st/f" ) // buildCore fixdoc diff --git a/internal/arduino/builder/internal/preprocessor/gcc.go b/internal/arduino/builder/internal/preprocessor/gcc.go index bfcc9512e0c..cbf156dfae6 100644 --- a/internal/arduino/builder/internal/preprocessor/gcc.go +++ b/internal/arduino/builder/internal/preprocessor/gcc.go @@ -21,11 +21,11 @@ import ( "fmt" "strings" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/builder/cpp" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "go.bug.st/f" ) // GCC performs a run of the gcc preprocess (macro/includes expansion). The function outputs the result diff --git a/internal/arduino/builder/internal/utils/utils.go b/internal/arduino/builder/internal/utils/utils.go index d0cb2cec48c..4b4d5b79416 100644 --- a/internal/arduino/builder/internal/utils/utils.go +++ b/internal/arduino/builder/internal/utils/utils.go @@ -21,9 +21,9 @@ import ( "strings" "unicode" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" + "go.bug.st/f" "golang.org/x/text/runes" "golang.org/x/text/transform" "golang.org/x/text/unicode/norm" diff --git a/internal/arduino/builder/libraries.go b/internal/arduino/builder/libraries.go index f5648a09596..6bb28f96ed2 100644 --- a/internal/arduino/builder/libraries.go +++ b/internal/arduino/builder/libraries.go @@ -20,12 +20,12 @@ import ( "strings" "time" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/builder/cpp" "github.com/arduino/arduino-cli/internal/arduino/libraries" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "go.bug.st/f" ) // nolint diff --git a/internal/arduino/builder/linker.go b/internal/arduino/builder/linker.go index e7d91811890..20032608db5 100644 --- a/internal/arduino/builder/linker.go +++ b/internal/arduino/builder/linker.go @@ -18,9 +18,9 @@ package builder import ( "strings" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/go-paths-helper" + "go.bug.st/f" ) // link fixdoc diff --git a/internal/arduino/builder/sketch.go b/internal/arduino/builder/sketch.go index 45612d9d313..1f64d207c81 100644 --- a/internal/arduino/builder/sketch.go +++ b/internal/arduino/builder/sketch.go @@ -25,11 +25,11 @@ import ( "strings" "fortio.org/safecast" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/builder/cpp" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/go-paths-helper" "github.com/marcinbor85/gohex" + "go.bug.st/f" ) var ( diff --git a/internal/arduino/sketch/sketch.go b/internal/arduino/sketch/sketch.go index 5cdfb6f3ee8..015be0b1f56 100644 --- a/internal/arduino/sketch/sketch.go +++ b/internal/arduino/sketch/sketch.go @@ -24,11 +24,11 @@ import ( "strings" "github.com/arduino/arduino-cli/commands/cmderrors" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/arduino/globals" "github.com/arduino/arduino-cli/internal/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" + "go.bug.st/f" ) // Sketch holds all the files composing a sketch diff --git a/internal/cli/arguments/completion.go b/internal/cli/arguments/completion.go index a8867c51cf2..9b6678fe9ac 100644 --- a/internal/cli/arguments/completion.go +++ b/internal/cli/arguments/completion.go @@ -18,9 +18,9 @@ package arguments import ( "context" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/cli/instance" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "go.bug.st/f" ) // GetInstalledBoards is an helper function useful to autocomplete. diff --git a/internal/cli/arguments/port.go b/internal/cli/arguments/port.go index fea0b475db5..1df918210e3 100644 --- a/internal/cli/arguments/port.go +++ b/internal/cli/arguments/port.go @@ -23,11 +23,11 @@ import ( "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands/cmderrors" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "go.bug.st/f" ) // Port contains the port arguments result. diff --git a/internal/cli/arguments/sketch.go b/internal/cli/arguments/sketch.go index 8a912e0dbc8..7f76f86e98c 100644 --- a/internal/cli/arguments/sketch.go +++ b/internal/cli/arguments/sketch.go @@ -18,12 +18,12 @@ package arguments import ( "context" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" + "go.bug.st/f" ) // InitSketchPath returns an instance of paths.Path pointing to sketchPath. diff --git a/internal/cli/config/config.go b/internal/cli/config/config.go index d05f43ff77c..dd42eb71213 100644 --- a/internal/cli/config/config.go +++ b/internal/cli/config/config.go @@ -20,12 +20,12 @@ import ( "os" "strings" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-paths-helper" "github.com/spf13/cobra" + "go.bug.st/f" ) // NewCommand created a new `config` command diff --git a/internal/cli/config/set.go b/internal/cli/config/set.go index 34c1d3168e2..34adb362811 100644 --- a/internal/cli/config/set.go +++ b/internal/cli/config/set.go @@ -20,12 +20,12 @@ import ( "encoding/json" "os" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "go.bug.st/f" ) func initSetCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command { diff --git a/internal/cli/feedback/result/rpc.go b/internal/cli/feedback/result/rpc.go index a1b464a89b1..9798e59584a 100644 --- a/internal/cli/feedback/result/rpc.go +++ b/internal/cli/feedback/result/rpc.go @@ -20,10 +20,10 @@ import ( "fmt" "slices" - f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/i18n" "github.com/arduino/arduino-cli/internal/orderedmap" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "go.bug.st/f" semver "go.bug.st/relaxed-semver" )