sourcegraph/dev/sg/sg_backport.go
Robert Lin 6212f2585c
chore/sg: clean up help formatting (#63860)
Noticed several `Usage` using newlines, which makes `-h` output pretty
annoying to read as it breaks up the formatting. It tickled me enough to
put a formatting check against it, and update the existing usages that
were incorrect, to use `Description` or `UsageText` instead :-)

## Test plan

CI, `sg -h` is pretty(er) again (but still very long)
2024-07-16 12:01:06 -07:00

46 lines
1.3 KiB
Go

package main
import (
"github.com/Masterminds/semver"
"github.com/urfave/cli/v2"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/backport"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/category"
"github.com/sourcegraph/sourcegraph/dev/sg/internal/std"
"github.com/sourcegraph/sourcegraph/lib/output"
)
var pullRequestIDFlag = cli.Int64Flag{
Name: "pullRequestID",
Usage: "The pull request ID to backport into the release branch",
Required: true,
Aliases: []string{"p"},
}
var releaseBranchFlag = cli.StringFlag{
Name: "releaseBranch",
Usage: "The release branch to backport the PR into",
Required: true,
Aliases: []string{"r"},
}
var backportCommand = &cli.Command{
Name: "backport",
Category: category.Dev,
Usage: "Backport commits from main to release branches",
UsageText: "sg backport -r 5.3 -p 60932",
Action: func(cmd *cli.Context) error {
prNumber := pullRequestIDFlag.Get(cmd)
releaseBranch := releaseBranchFlag.Get(cmd)
_, err := semver.NewVersion(releaseBranch)
if err != nil {
return err
}
std.Out.WriteLine(output.Styledf(output.StylePending, "Backporting commits from main to release branch %q for PR %d...", releaseBranch, prNumber))
return backport.Run(cmd, prNumber, releaseBranch)
},
Flags: []cli.Flag{&pullRequestIDFlag, &releaseBranchFlag},
}