Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Examples:
}

// Determine which variables to use in the request.
vars := map[string]interface{}{}
vars := map[string]any{}
if *varsFlag != "" {
if err := json.Unmarshal([]byte(*varsFlag), &vars); err != nil {
return err
Expand All @@ -93,7 +93,7 @@ Examples:
}

// Perform the request.
var result interface{}
var result any
if ok, err := cfg.apiClient(apiFlags, flagSet.Output()).NewRequest(query, vars).DoRaw(context.Background(), &result); err != nil || !ok {
return err
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/src/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"slices"

"github.com/sourcegraph/src-cli/internal/cmderrors"
)
Expand All @@ -30,12 +31,7 @@ func (c *command) matches(name string) bool {
if name == c.flagSet.Name() {
return true
}
for _, alias := range c.aliases {
if name == alias {
return true
}
}
return false
return slices.Contains(c.aliases, name)
}

// commander represents a top-level command with subcommands.
Expand All @@ -60,7 +56,6 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []

// Configure default usage funcs for commands.
for _, cmd := range c {
cmd := cmd
if cmd.usageFunc != nil {
cmd.flagSet.Usage = cmd.usageFunc
continue
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/code_intel_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func handleCodeIntelUpload(args []string) error {
}

if codeintelUploadFlags.json {
serialized, err := json.Marshal(map[string]interface{}{
serialized, err := json.Marshal(map[string]any{
"repo": codeintelUploadFlags.repo,
"commit": codeintelUploadFlags.commit,
"root": codeintelUploadFlags.root,
Expand Down Expand Up @@ -202,7 +202,7 @@ func makeCodeIntelUploadURL(uploadID int) (string, error) {
return "", err
}

graphqlID := base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`SCIPUpload:%d`, uploadID)))
graphqlID := base64.URLEncoding.EncodeToString(fmt.Appendf(nil, `SCIPUpload:%d`, uploadID))
url.Path = codeintelUploadFlags.repo + "/-/code-intelligence/uploads/" + graphqlID
url.User = nil
return url.String(), nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/codeowners_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Examples:
var result struct {
AddCodeownersFile CodeownersIngestedFile
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"repoName": *repoFlag,
"content": string(content),
}).Do(context.Background(), &result); err != nil || !ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/codeowners_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Examples:
var result struct {
DeleteCodeownersFile CodeownersIngestedFile
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"repoName": *repoFlag,
}).Do(context.Background(), &result); err != nil || !ok {
var gqlErr api.GraphQlErrors
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/codeowners_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Examples:
IngestedCodeowners *CodeownersIngestedFile
}
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"repoName": *repoFlag,
}).Do(context.Background(), &result); err != nil || !ok {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/codeowners_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Examples:
var result struct {
UpdateCodeownersFile CodeownersIngestedFile
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"repoName": *repoFlag,
"content": string(content),
}).Do(context.Background(), &result); err != nil || !ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ query SettingsSubjectLatestSettingsID($subject: ID!) {
}
}

if _, err := client.NewRequest(query, map[string]interface{}{
if _, err := client.NewRequest(query, map[string]any{
"subject": subjectID,
}).Do(ctx, &result); err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/src/config_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ mutation EditSettings($input: SettingsMutationGroupInput!, $edit: SettingsEdit!)
}
}
}`
queryVars := map[string]interface{}{
"input": map[string]interface{}{
queryVars := map[string]any{
"input": map[string]any{
"subject": subjectID,
"lastID": lastID,
},
"edit": map[string]interface{}{
"edit": map[string]any{
"keyPath": keyPath,
"value": value,
"valueIsJSONCEncodedString": true,
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Examples:
}

var query string
var queryVars map[string]interface{}
var queryVars map[string]any
if *subjectFlag == "" {
query = viewerSettingsQuery
} else {
query = settingsSubjectCascadeQuery
queryVars = map[string]interface{}{
queryVars = map[string]any{
"subject": api.NullString(*subjectFlag),
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/config_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ Examples:
}

var query string
var queryVars map[string]interface{}
var queryVars map[string]any
if *subjectFlag == "" {
query = viewerSettingsQuery
} else {
query = settingsSubjectCascadeQuery
queryVars = map[string]interface{}{
queryVars = map[string]any{
"subject": api.NullString(*subjectFlag),
}
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/src/debug_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs

// start goroutine to run docker container logs <container>
for _, container := range containers {
container := container
run(func() *archiveFile { return getContainerLog(ctx, container, baseDir) })
}

// start goroutine to run docker container inspect <container>
for _, container := range containers {
container := container
run(func() *archiveFile { return getInspect(ctx, container, baseDir) })
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/src/extsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func lookupExternalService(ctx context.Context, client api.Client, byID, byName
Nodes []*externalService
}
}
if ok, err := client.NewRequest(externalServicesListQuery, map[string]interface{}{
if ok, err := client.NewRequest(externalServicesListQuery, map[string]any{
"first": 99999,
}).Do(ctx, &result); err != nil || !ok {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/extsvc_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func init() {
}
}

createExternalServiceInput := map[string]interface{}{
createExternalServiceInput := map[string]any{
"kind": strings.ToUpper(*kindFlag),
"displayName": *nameFlag,
"config": string(createJSON),
}
queryVars := map[string]interface{}{
queryVars := map[string]any{
"input": createExternalServiceInput,
}
var result struct{} // TODO: future: allow formatting resulting external service
Expand Down
18 changes: 9 additions & 9 deletions cmd/src/extsvc_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Examples:
updateJSON = []byte(updated)
}

updateExternalServiceInput := map[string]interface{}{
updateExternalServiceInput := map[string]any{
"id": id,
}
if *renameFlag != "" {
Expand All @@ -115,7 +115,7 @@ Examples:
return nil // nothing to update
}

queryVars := map[string]interface{}{
queryVars := map[string]any{
"input": updateExternalServiceInput,
}
var result struct{} // TODO: future: allow formatting resulting external service
Expand Down Expand Up @@ -151,23 +151,23 @@ mutation ($input: UpdateExternalServiceInput!) {
// doesn't exist.
func appendExcludeRepositories(input string, excludeRepoNames []string) (string, error) {
// Known issue: Comments are not retained in the existing array value.
var m interface{}
var m any
if err := jsonxUnmarshal(input, &m); err != nil {
return "", err
}
root, ok := m.(map[string]interface{})
root, ok := m.(map[string]any)
if !ok {
return "", errors.New("existing JSONx external service configuration is invalid (not an object)")
}
var exclude []interface{}
var exclude []any
alreadyExcludedNames := map[string]struct{}{}
if existing, ok := root["exclude"]; ok {
exclude, ok = existing.([]interface{})
exclude, ok = existing.([]any)
if !ok {
return "", errors.New("existing JSONx external service configuration is invalid (exclude is not an array)")
}
for i, exclude := range exclude {
obj, ok := exclude.(map[string]interface{})
obj, ok := exclude.(map[string]any)
if !ok {
return "", fmt.Errorf("existing JSONx external service configuration is invalid (exclude.%d is not object)", i)
}
Expand All @@ -189,7 +189,7 @@ func appendExcludeRepositories(input string, excludeRepoNames []string) (string,
if _, already := alreadyExcludedNames[repoName]; already {
continue
}
exclude = append(exclude, map[string]interface{}{
exclude = append(exclude, map[string]any{
"name": repoName,
})
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func jsonxToJSON(text string) ([]byte, error) {
// jsonxUnmarshal unmarshals jsonx into Go data.
//
// This process loses comments, trailing commas, formatting, etc.
func jsonxUnmarshal(text string, v interface{}) error {
func jsonxUnmarshal(text string, v any) error {
data, err := jsonxToJSON(text)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/extsvc_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Examples:
ctx := context.Background()
client := cfg.apiClient(apiFlags, flagSet.Output())

queryVars := map[string]interface{}{
queryVars := map[string]any{
"first": first,
}
var result externalServicesListResult
Expand Down Expand Up @@ -99,7 +99,7 @@ const externalServicesListQuery = `
// Typing here is primarily for ordering of results as we format them (maps are unordered).
type externalServicesListResult struct {
ExternalServices struct {
Nodes []map[string]interface{}
Nodes []map[string]any
TotalCount int
PageInfo struct {
HasNextPage bool
Expand Down
26 changes: 10 additions & 16 deletions cmd/src/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

func parseTemplate(text string) (*template.Template, error) {
tmpl := template.New("")
tmpl.Funcs(map[string]interface{}{
tmpl.Funcs(map[string]any{
"join": strings.Join,
"json": func(v interface{}) (string, error) {
"json": func(v any) (string, error) {
b, err := marshalIndent(v)
return string(b), err
},
Expand All @@ -26,26 +26,20 @@ func parseTemplate(text string) (*template.Template, error) {
"msDuration": func(ms int) time.Duration {
return time.Duration(ms) * time.Millisecond
},
"repoNames": func(repos []map[string]interface{}) (names []string) {
"repoNames": func(repos []map[string]any) (names []string) {
for _, r := range repos {
names = append(names, r["name"].(string))
}
return
},
"pad": func(value interface{}, padding int, padCharacter string) string {
"pad": func(value any, padding int, padCharacter string) string {
val := fmt.Sprint(value)
repeat := padding - len(val)
if repeat < 0 {
repeat = 0
}
repeat := max(padding-len(val), 0)
return strings.Repeat(padCharacter, repeat) + val
},
"padRight": func(value interface{}, padding int, padCharacter string) string {
"padRight": func(value any, padding int, padCharacter string) string {
val := fmt.Sprint(value)
repeat := padding - len(val)
if repeat < 0 {
repeat = 0
}
repeat := max(padding-len(val), 0)
return val + strings.Repeat(padCharacter, repeat)
},
"indent": func(lines, indention string) string {
Expand All @@ -60,7 +54,7 @@ func parseTemplate(text string) (*template.Template, error) {
"addFloat": func(x, y float64) float64 {
return x + y
},
"debug": func(v interface{}) string {
"debug": func(v any) string {
data, _ := marshalIndent(v)
fmt.Println(string(data))

Expand Down Expand Up @@ -111,7 +105,7 @@ func parseTemplate(text string) (*template.Template, error) {
return tmpl.Parse(text)
}

func execTemplate(tmpl *template.Template, data interface{}) error {
func execTemplate(tmpl *template.Template, data any) error {
if err := tmpl.Execute(os.Stdout, data); err != nil {
return err
}
Expand All @@ -120,6 +114,6 @@ func execTemplate(tmpl *template.Template, data interface{}) error {
}

// json.MarshalIndent, but with defaults.
func marshalIndent(v interface{}) ([]byte, error) {
func marshalIndent(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
4 changes: 2 additions & 2 deletions cmd/src/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func parseAdditionalHeadersFromEnviron(environ []string) map[string]string {
// Most shell convert line breaks added to a string, so we need to replace all occurence of the stringified line
// breaks to actual line breaks.
headers = strings.ReplaceAll(headers, `\n`, "\n")
splitHeaders := strings.Split(headers, "\n")
splitHeaders := strings.SplitSeq(headers, "\n")

for _, h := range splitHeaders {
for h := range splitHeaders {
p := strings.SplitN(h, ":", 2)
if len(p) != 2 || p[1] == "" {
continue
Expand Down
7 changes: 1 addition & 6 deletions cmd/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,7 @@ func readConfig() (*config, error) {
urlSchemes := []string{"http", "https", "socks", "socks5", "socks5h"}

isURLScheme := func(scheme string) bool {
for _, s := range urlSchemes {
if scheme == s {
return true
}
}
return false
return slices.Contains(urlSchemes, scheme)
}

scheme, address := parseEndpoint(cfg.Proxy)
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/orgs_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Examples:
var result struct {
CreateOrg Org
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"name": *nameFlag,
"displayName": *displayNameFlag,
}).Do(context.Background(), &result); err != nil || !ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/orgs_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Examples:
var result struct {
DeleteOrganization struct{}
}
if ok, err := client.NewRequest(query, map[string]interface{}{
if ok, err := client.NewRequest(query, map[string]any{
"organization": *orgIDFlag,
}).Do(context.Background(), &result); err != nil || !ok {
return err
Expand Down
Loading
Loading