Skip to content

Commit

Permalink
fix: Fix command.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSMLG-BOT committed Apr 18, 2024
1 parent da09249 commit 5b5ba08
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/httpbenchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -77,7 +76,7 @@ var httpbenchmarkCmd = &cobra.Command{
if stream {
bodyFile = fileName
} else {
bodyBytes, err = ioutil.ReadFile(fileName)
bodyBytes, err = os.ReadFile(fileName)
if err != nil {
errAndExit(err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/publicKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand All @@ -34,7 +34,7 @@ Use --private-key or -p to set private key, "-" indicate stdin.`,
log.Fatal(err)
}
}
c, err := ioutil.ReadAll(f)
c, err := io.ReadAll(f)
if err != nil {
log.Fatal(err)
}
Expand Down
51 changes: 51 additions & 0 deletions cmd/replace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2022 Jonathan Gao <[email protected]>
*/
package cmd

import (
"github.com/spf13/cobra"
)

// replaceCmd replace strings
var replaceCmd = &cobra.Command{
Use: "replace",
Short: "replace string in directory.",
Long: `replace string in directory.
gsmlg-cli replace --from "<name1>" --to "<name2>" --only-in <dir?>.`,
Run: func(cmd *cobra.Command, args []string) {
from, err := cmd.Flags().GetString("from")
exitIfError(err)
to, err := cmd.Flags().GetString("to")
exitIfError(err)
onlyIn, err := cmd.Flags().GetString("only-in")
exitIfError(err)

if from != "" || to != "" {
if onlyIn != "" {
// replace in only in dir

} else {
// replace in cwd
}
} else if to == "" || from != "" {
// replace to is empty, do search only
if onlyIn != "" {
// search in only in dir
} else {
// search in cwd
}
} else {
// print help
cmd.Help()
}
},
}

func init() {
rootCmd.AddCommand(replaceCmd)

replaceCmd.Flags().StringP("from", "f", "", "replace from")
replaceCmd.Flags().StringP("to", "t", "", "replace to")
replaceCmd.Flags().StringP("only-in", "d", "", "replace only in directory")
}

0 comments on commit 5b5ba08

Please sign in to comment.