Drop references to io/ioutil (#403)
io/ioutil has been deprecated for a while. Replace all uses of it with equivalent APIs.
This commit is contained in:
@@ -76,7 +76,6 @@ issues:
|
|||||||
- 'bad syntax for struct tag key'
|
- 'bad syntax for struct tag key'
|
||||||
- 'bad syntax for struct tag pair'
|
- 'bad syntax for struct tag pair'
|
||||||
- 'result .* \(error\) is always nil'
|
- 'result .* \(error\) is always nil'
|
||||||
- 'package io/ioutil is deprecated'
|
|
||||||
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
# Don't warn on unused parameters.
|
# Don't warn on unused parameters.
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ var cli struct {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Debug logger going to discard.
|
// Debug logger going to discard.
|
||||||
logger := log.New(ioutil.Discard, "", log.LstdFlags)
|
logger := log.New(io.Discard, "", log.LstdFlags)
|
||||||
|
|
||||||
ctx := kong.Parse(&cli, kong.Bind(logger))
|
ctx := kong.Parse(&cli, kong.Bind(logger))
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,6 @@ package kong_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ func TestConfigValidation(t *testing.T) {
|
|||||||
|
|
||||||
func makeConfig(t *testing.T, config interface{}) (path string, cleanup func()) {
|
func makeConfig(t *testing.T, config interface{}) (path string, cleanup func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
w, err := ioutil.TempFile("", "")
|
w, err := os.CreateTemp("", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
err = json.NewEncoder(w).Encode(config)
|
err = json.NewEncoder(w).Encode(config)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -712,9 +712,9 @@ func fileContentMapper(r *Registry) MapperFunc {
|
|||||||
var data []byte
|
var data []byte
|
||||||
if path != "-" {
|
if path != "-" {
|
||||||
path = ExpandPath(path)
|
path = ExpandPath(path)
|
||||||
data, err = ioutil.ReadFile(path) //nolint:gosec
|
data, err = os.ReadFile(path) //nolint:gosec
|
||||||
} else {
|
} else {
|
||||||
data, err = ioutil.ReadAll(os.Stdin)
|
data, err = io.ReadAll(os.Stdin)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if info, statErr := os.Stat(path); statErr == nil && info.IsDir() {
|
if info, statErr := os.Stat(path); statErr == nil && info.IsDir() {
|
||||||
@@ -884,7 +884,7 @@ func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { //nolint: revi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
filename = ExpandPath(filename)
|
filename = ExpandPath(filename)
|
||||||
data, err := ioutil.ReadFile(filename) //nolint: gosec
|
data, err := os.ReadFile(filename) //nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open %q: %v", filename, err)
|
return fmt.Errorf("failed to open %q: %v", filename, err)
|
||||||
}
|
}
|
||||||
@@ -908,7 +908,7 @@ func (f *FileContentFlag) Decode(ctx *DecodeContext) error { //nolint: revive
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
filename = ExpandPath(filename)
|
filename = ExpandPath(filename)
|
||||||
data, err := ioutil.ReadFile(filename) //nolint: gosec
|
data, err := os.ReadFile(filename) //nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open %q: %v", filename, err)
|
return fmt.Errorf("failed to open %q: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -269,7 +268,7 @@ func TestFileContentFlag(t *testing.T) {
|
|||||||
var cli struct {
|
var cli struct {
|
||||||
File kong.FileContentFlag
|
File kong.FileContentFlag
|
||||||
}
|
}
|
||||||
f, err := ioutil.TempFile("", "")
|
f, err := os.CreateTemp("", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
fmt.Fprint(f, "hello world")
|
fmt.Fprint(f, "hello world")
|
||||||
@@ -283,7 +282,7 @@ func TestNamedFileContentFlag(t *testing.T) {
|
|||||||
var cli struct {
|
var cli struct {
|
||||||
File kong.NamedFileContentFlag
|
File kong.NamedFileContentFlag
|
||||||
}
|
}
|
||||||
f, err := ioutil.TempFile("", "")
|
f, err := os.CreateTemp("", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
fmt.Fprint(f, "hello world")
|
fmt.Fprint(f, "hello world")
|
||||||
|
|||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package kong
|
package kong
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -17,7 +16,7 @@ func TestConfigFlag(t *testing.T) {
|
|||||||
Flag string
|
Flag string
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := ioutil.TempFile("", "")
|
w, err := os.CreateTemp("", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(w.Name())
|
defer os.Remove(w.Name())
|
||||||
w.WriteString(`{"flag": "hello world"}`) //nolint: errcheck
|
w.WriteString(`{"flag": "hello world"}`) //nolint: errcheck
|
||||||
|
|||||||
Reference in New Issue
Block a user