Skip to content

Commit

Permalink
(chore) rename "repo {add|update|delete}-kvp" to "repo {add|update|de…
Browse files Browse the repository at this point in the history
…lete}-metadata" (#972)
  • Loading branch information
erzhtor authored Apr 24, 2023
1 parent f5469f2 commit ea9e501
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to `src-cli` are documented in this file.
### Added

### Changed
- Renamed `src repo {add|update|delete}-kvp` to `repo {add|update|delete}-metadata` [#972](https://github.com/sourcegraph/src-cli/pull/972)

### Fixed

Expand Down
12 changes: 6 additions & 6 deletions cmd/src/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Usage:
The commands are:
get gets a repository
list lists repositories
delete deletes repositories
add-kvp adds a key-value pair to a repository
update-kvp updates a key-value pair on a repository
delete-kvp deletes a key-value pair from a repository
get gets a repository
list lists repositories
delete deletes repositories
add-metadata adds a key-value pair metadata to a repository
update-metadata updates a key-value pair metadata on a repository
delete-metadata deletes a key-value pair metadata from a repository
Use "src repos [command] -h" for more information about a command.
`
Expand Down
21 changes: 12 additions & 9 deletions cmd/src/repos_add_kvp.go → cmd/src/repos_add_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ func init() {
usage := `
Examples:
Add a key-value pair to a repository:
Add a key-value pair metadata to a repository:
$ src repos add-kvp -repo=repoID -key=mykey -value=myvalue
$ src repos add-metadata -repo=repoID -key=mykey -value=myvalue
Omitting -value will create a tag (a key with a null value).
[DEPRECATED] Note that 'add-kvp' is deprecated and will be removed in future release. Use 'add-metadata' instead.
`

flagSet := flag.NewFlagSet("add-kvp", flag.ExitOnError)
flagSet := flag.NewFlagSet("add-metadata", flag.ExitOnError)
usageFunc := func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src repos %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Println(usage)
}
var (
repoFlag = flagSet.String("repo", "", `The ID of the repo to add the key-value pair to (required)`)
keyFlag = flagSet.String("key", "", `The name of the key to add (required)`)
valueFlag = flagSet.String("value", "", `The value associated with the key. Defaults to null.`)
repoFlag = flagSet.String("repo", "", `The ID of the repo to add the key-value pair metadata to (required)`)
keyFlag = flagSet.String("key", "", `The name of the metadata key to add (required)`)
valueFlag = flagSet.String("value", "", `The metadata value associated with the metadata key. Defaults to null.`)
apiFlags = api.NewFlags(flagSet)
)

Expand Down Expand Up @@ -60,7 +62,7 @@ Examples:

client := cfg.apiClient(apiFlags, flagSet.Output())

query := `mutation addKVP(
query := `mutation addRepoMetadata(
$repo: ID!,
$key: String!,
$value: String,
Expand All @@ -83,16 +85,17 @@ Examples:
}

if valueFlag != nil {
fmt.Printf("Key-value pair '%s:%v' created.\n", *keyFlag, *valueFlag)
fmt.Printf("Key-value pair metadata '%s:%v' created.\n", *keyFlag, *valueFlag)
} else {
fmt.Printf("Key-value pair '%s:<nil>' created.\n", *keyFlag)
fmt.Printf("Key-value pair metadata '%s:<nil>' created.\n", *keyFlag)
}
return nil
}

// Register the command.
reposCommands = append(reposCommands, &command{
flagSet: flagSet,
aliases: []string{"add-kvp"},
handler: handler,
usageFunc: usageFunc,
})
Expand Down
17 changes: 10 additions & 7 deletions cmd/src/repos_delete_kvp.go → cmd/src/repos_delete_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ import (
"fmt"

"github.com/sourcegraph/sourcegraph/lib/errors"

"github.com/sourcegraph/src-cli/internal/api"
)

func init() {
usage := `
Examples:
Delete a key-value pair from a repository:
Delete a key-value pair metadata from a repository:
$ src repos delete-kvp -repo=repoID -key=mykey
$ src repos delete-metadata -repo=repoID -key=mykey
[DEPRECATED] Note 'delete-kvp' is deprecated and will be removed in future release. Use 'delete-metadata' instead.
`

flagSet := flag.NewFlagSet("delete-kvp", flag.ExitOnError)
flagSet := flag.NewFlagSet("delete-metadata", flag.ExitOnError)
usageFunc := func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src repos %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Println(usage)
}
var (
repoFlag = flagSet.String("repo", "", `The ID of the repo with the key-value pair to be deleted (required)`)
keyFlag = flagSet.String("key", "", `The name of the key to be deleted (required)`)
repoFlag = flagSet.String("repo", "", `The ID of the repo with the key-value pair metadata to be deleted (required)`)
keyFlag = flagSet.String("key", "", `The name of the metadata key to be deleted (required)`)
apiFlags = api.NewFlags(flagSet)
)

Expand All @@ -52,7 +54,7 @@ Examples:

client := cfg.apiClient(apiFlags, flagSet.Output())

query := `mutation deleteKVP(
query := `mutation deleteRepoMetadata(
$repo: ID!,
$key: String!,
) {
Expand All @@ -71,13 +73,14 @@ Examples:
return err
}

fmt.Printf("Key-value pair with key '%s' deleted.\n", *keyFlag)
fmt.Printf("Key-value pair metadata with key '%s' deleted.\n", *keyFlag)
return nil
}

// Register the command.
reposCommands = append(reposCommands, &command{
flagSet: flagSet,
aliases: []string{"delete-kvp"},
handler: handler,
usageFunc: usageFunc,
})
Expand Down
17 changes: 10 additions & 7 deletions cmd/src/repos_update_kvp.go → cmd/src/repos_update_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ func init() {
usage := `
Examples:
Update the value for a key on a repository:
Update the metadata value for a metadata key on a repository:
$ src repos update-kvp -repo=repoID -key=my-key -value=new-value
$ src repos update-metadata -repo=repoID -key=my-key -value=new-value
Omitting -value will set the value of the key to null.
[DEPRECATED] Note that 'update-kvp' is deprecated and will be removed in future release. Use 'update-metadata' instead.
`

flagSet := flag.NewFlagSet("update-kvp", flag.ExitOnError)
flagSet := flag.NewFlagSet("update-metadata", flag.ExitOnError)
usageFunc := func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src repos %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Println(usage)
}
var (
repoFlag = flagSet.String("repo", "", `The ID of the repo with the key to be updated (required)`)
keyFlag = flagSet.String("key", "", `The name of the key to be updated (required)`)
valueFlag = flagSet.String("value", "", `The new value of the key to be set. Defaults to null.`)
repoFlag = flagSet.String("repo", "", `The ID of the repo with the metadata key to be updated (required)`)
keyFlag = flagSet.String("key", "", `The name of the metadata key to be updated (required)`)
valueFlag = flagSet.String("value", "", `The new metadata value of the metadata key to be set. Defaults to null.`)
apiFlags = api.NewFlags(flagSet)
)

Expand Down Expand Up @@ -60,7 +62,7 @@ Examples:

client := cfg.apiClient(apiFlags, flagSet.Output())

query := `mutation updateKVP(
query := `mutation updateMetadata(
$repo: ID!,
$key: String!,
$value: String,
Expand Down Expand Up @@ -93,6 +95,7 @@ Examples:
// Register the command.
reposCommands = append(reposCommands, &command{
flagSet: flagSet,
aliases: []string{"update-kvp"},
handler: handler,
usageFunc: usageFunc,
})
Expand Down

0 comments on commit ea9e501

Please sign in to comment.