sourcegraph/dev/sg/sg_rfc.go
Rafał Gajdulewicz 7211c8cdb2
[sg] Make rfc command use private RFCs by default (#63902)
This PR changes the `sg rfc` command to introduce a new flag `--public`
(previously, an implicit default) and removes the flag `--private` (new
default).

This change implements part of our new approach to RFCs (private by
default,
[context](https://sourcegraph.slack.com/archives/C03L2R35ENL/p1719013625952019)
[need to
follow-up](https://sourcegraph.slack.com/archives/C01GNBB34FR/p1720813994240309?thread_ts=1720626835.727909&cid=C01GNBB34FR)).

## Test plan

- ran `sg rfc create "test new default"` and a private
[RFC](https://docs.google.com/document/d/1gGrejPvHQaeKPrHr4PW_XxdArZQ4iUAWxlhkjglaNQc/edit#heading=h.trqab8y0kufp)
was created
- ran `sg rfc --public create "test public"` and a public
[RFC](https://docs.google.com/document/d/1K_ElZWyvCNV3QMGoBr9-h4L0h_2wswbVauEjmzD6shk/edit#heading=h.trqab8y0kufp)
was created
- ran `sg rfc list` and private RFCs were listed
- ran `sg rfc --public list` and public RFCs were listed
2024-07-18 14:12:28 +02:00

158 lines
4.0 KiB
Go

package main
import (
"fmt"
"strings"
"github.com/urfave/cli/v2"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/category"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/rfc"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/std"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
var rfcCommand = &cli.Command{
Name: "rfc",
Usage: `List, search, and open Sourcegraph RFCs`,
Description: fmt.Sprintf("Sourcegraph RFCs live in the following drives - see flags to configure which drive to query:\n\n%s", func() (out string) {
for _, d := range []rfc.DriveSpec{rfc.PublicDrive, rfc.PrivateDrive} {
out += fmt.Sprintf("* %s: https://drive.google.com/drive/folders/%s\n", d.DisplayName, d.FolderID)
}
return out
}()),
UsageText: `
# List all Public RFCs
sg rfc --public list
# List all Private RFCs
sg rfc list
# List all Private RFCs that match one of some statuses
sg rfc list -s approved -s implemented -s done
# Search for a Public RFC
sg rfc --public search "search terms"
# Search for a Private RFC
sg rfc search "search terms"
# Open a specific Private RFC
sg rfc open 420
# Open a specific Public RFC
sg rfc --public open 420
# Create a new public RFC
sg rfc --public create "title"
# Create a new private RFC. Possible types: [solution]
sg rfc create --type <type> "title"
`,
Category: category.Company,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "public",
Usage: "perform the RFC action on the public RFC drive",
Required: false,
Value: false,
},
},
Subcommands: []*cli.Command{
{
Name: "list",
ArgsUsage: " ",
Usage: "List Sourcegraph RFCs",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "status",
Aliases: []string{"s"},
Usage: "Only show RFCs with the given status(es)",
},
},
Action: func(c *cli.Context) error {
driveSpec := rfc.PrivateDrive
if c.Bool("public") {
driveSpec = rfc.PublicDrive
}
return rfc.List(c.Context, driveSpec, std.Out, c.StringSlice("status"))
},
},
{
Name: "search",
ArgsUsage: "[query]",
Usage: "Search Sourcegraph RFCs",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "status",
Aliases: []string{"s"},
Usage: "Only show RFCs with the given status(es)",
},
},
Action: func(c *cli.Context) error {
driveSpec := rfc.PrivateDrive
if c.Bool("public") {
driveSpec = rfc.PublicDrive
}
if c.Args().Len() == 0 {
return errors.New("no search query given")
}
return rfc.Search(c.Context, strings.Join(c.Args().Slice(), " "), driveSpec, std.Out, c.StringSlice("status"))
},
},
{
Name: "open",
ArgsUsage: "[number]",
Usage: "Open a Sourcegraph RFC - find and list RFC numbers with 'sg rfc list' or 'sg rfc search'",
Action: func(c *cli.Context) error {
driveSpec := rfc.PrivateDrive
if c.Bool("public") {
driveSpec = rfc.PublicDrive
}
if c.Args().Len() == 0 {
return errors.New("no RFC given")
}
return rfc.Open(c.Context, c.Args().First(), driveSpec, std.Out)
},
},
{
Name: "create",
ArgsUsage: "--type <type> [title...]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "type",
Usage: "the type of the RFC to create (valid: solution)",
Value: rfc.ProblemSolutionDriveTemplate.Name,
},
},
Usage: "Create Sourcegraph RFCs",
Action: func(c *cli.Context) error {
driveSpec := rfc.PrivateDrive
if c.Bool("public") {
driveSpec = rfc.PublicDrive
}
rfcType := c.String("type")
var template rfc.Template
// Search for the rfcType and assign it to template
for _, tpl := range rfc.AllTemplates {
if tpl.Name == rfcType {
template = tpl
break
}
}
if template.Name == "" {
return errors.New(fmt.Sprintf("Unknown RFC type: %s", rfcType))
}
if c.Args().Len() == 0 {
return errors.New("no title given")
}
return rfc.Create(c.Context, template, strings.Join(c.Args().Slice(), " "),
driveSpec, std.Out)
},
},
},
}