feat(build): add workflowPath CLI alias

This commit is contained in:
Virgil 2026-04-02 02:09:22 +00:00
parent 4ab4cc77c5
commit ce1de925be
2 changed files with 22 additions and 4 deletions

View file

@ -15,6 +15,7 @@ import (
var (
releaseWorkflowPathInput string
releaseWorkflowWorkflowPathInput string
releaseWorkflowWorkflowPathHyphenInput string
releaseWorkflowWorkflowPathSnakeInput string
releaseWorkflowOutputPathHyphenInput string
@ -29,6 +30,7 @@ var (
// rather than by call-site position.
type releaseWorkflowInputs struct {
pathInput string
workflowPathInput string
workflowPathHyphenInput string
workflowPathSnakeInput string
outputPathHyphenInput string
@ -44,6 +46,7 @@ var releaseWorkflowCmd = &cli.Command{
RunE: func(cmd *cli.Command, args []string) error {
return runReleaseWorkflow(cmd.Context(), releaseWorkflowInputs{
pathInput: releaseWorkflowPathInput,
workflowPathInput: releaseWorkflowWorkflowPathInput,
workflowPathHyphenInput: releaseWorkflowWorkflowPathHyphenInput,
workflowPathSnakeInput: releaseWorkflowWorkflowPathSnakeInput,
outputPathHyphenInput: releaseWorkflowOutputPathHyphenInput,
@ -63,6 +66,7 @@ func setWorkflowI18n() {
func initWorkflowFlags() {
releaseWorkflowCmd.Flags().StringVar(&releaseWorkflowPathInput, "path", "", i18n.T("cmd.build.workflow.flag.path"))
releaseWorkflowCmd.Flags().StringVar(&releaseWorkflowWorkflowPathInput, "workflowPath", "", i18n.T("cmd.build.workflow.flag.path"))
releaseWorkflowCmd.Flags().StringVar(&releaseWorkflowWorkflowPathHyphenInput, "workflow-path", "", i18n.T("cmd.build.workflow.flag.path"))
releaseWorkflowCmd.Flags().StringVar(&releaseWorkflowWorkflowPathSnakeInput, "workflow_path", "", i18n.T("cmd.build.workflow.flag.path"))
releaseWorkflowCmd.Flags().StringVar(&releaseWorkflowOutputPathHyphenInput, "output-path", "", i18n.T("cmd.build.workflow.flag.output_path"))
@ -86,6 +90,7 @@ func AddWorkflowCommand(buildCmd *cli.Command) {
// buildcmd.AddWorkflowCommand(buildCmd)
// runReleaseWorkflow(ctx, releaseWorkflowInputs{}) // writes to .github/workflows/release.yml
// runReleaseWorkflow(ctx, releaseWorkflowInputs{pathInput: "ci/release.yml"}) // writes to ./ci/release.yml under the project root
// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathInput: "ci/release.yml"}) // uses the workflowPath alias
// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathHyphenInput: "ci/release.yml"}) // uses the workflow-path alias
// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathSnakeInput: "ci/release.yml"}) // uses the workflow_path alias
// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputPathInput: "ci/release.yml"}) // uses the workflowOutputPath alias
@ -98,6 +103,7 @@ func runReleaseWorkflow(_ context.Context, inputs releaseWorkflowInputs) error {
resolvedWorkflowPath, err := resolveReleaseWorkflowInputPathAliases(
projectDir,
inputs.pathInput,
inputs.workflowPathInput,
inputs.workflowPathHyphenInput,
inputs.workflowPathSnakeInput,
)
@ -123,12 +129,12 @@ func runReleaseWorkflow(_ context.Context, inputs releaseWorkflowInputs) error {
// resolveReleaseWorkflowInputPathAliases keeps the CLI error wording stable while
// delegating the conflict detection to the shared build helper.
func resolveReleaseWorkflowInputPathAliases(projectDir, pathInput, workflowPathHyphenInput, workflowPathSnakeInput string) (string, error) {
func resolveReleaseWorkflowInputPathAliases(projectDir, pathInput, workflowPathInput, workflowPathHyphenInput, workflowPathSnakeInput string) (string, error) {
resolvedWorkflowPath, err := build.ResolveReleaseWorkflowInputPathAliases(
io.Local,
projectDir,
pathInput,
"",
workflowPathInput,
workflowPathSnakeInput,
workflowPathHyphenInput,
)

View file

@ -88,7 +88,15 @@ func TestBuildCmd_resolveReleaseWorkflowOutputPathAliases_AbsoluteEquivalent_Goo
func TestBuildCmd_resolveReleaseWorkflowInputPathAliases_Good(t *testing.T) {
projectDir := t.TempDir()
path, err := resolveReleaseWorkflowInputPathAliases(projectDir, "ci/release.yml", "", "")
path, err := resolveReleaseWorkflowInputPathAliases(projectDir, "ci/release.yml", "", "", "")
require.NoError(t, err)
assert.Equal(t, ax.Join(projectDir, "ci", "release.yml"), path)
}
func TestBuildCmd_resolveReleaseWorkflowInputPathAliases_WorkflowPathGood(t *testing.T) {
projectDir := t.TempDir()
path, err := resolveReleaseWorkflowInputPathAliases(projectDir, "", "ci/release.yml", "", "")
require.NoError(t, err)
assert.Equal(t, ax.Join(projectDir, "ci", "release.yml"), path)
}
@ -96,7 +104,7 @@ func TestBuildCmd_resolveReleaseWorkflowInputPathAliases_Good(t *testing.T) {
func TestBuildCmd_resolveReleaseWorkflowInputPathAliases_Bad(t *testing.T) {
projectDir := t.TempDir()
_, err := resolveReleaseWorkflowInputPathAliases(projectDir, "ci/release.yml", "ops/release.yml", "")
_, err := resolveReleaseWorkflowInputPathAliases(projectDir, "ci/release.yml", "ops/release.yml", "", "")
require.Error(t, err)
assert.Contains(t, err.Error(), "workflow path aliases specify different locations")
}
@ -123,6 +131,7 @@ func TestBuildCmd_RunReleaseWorkflow_Good(t *testing.T) {
AddWorkflowCommand(buildCmd)
pathFlag := releaseWorkflowCmd.Flags().Lookup("path")
workflowPathCamelFlag := releaseWorkflowCmd.Flags().Lookup("workflowPath")
workflowPathFlag := releaseWorkflowCmd.Flags().Lookup("workflow-path")
workflowPathSnakeFlag := releaseWorkflowCmd.Flags().Lookup("workflow_path")
outputPathFlag := releaseWorkflowCmd.Flags().Lookup("output-path")
@ -133,6 +142,7 @@ func TestBuildCmd_RunReleaseWorkflow_Good(t *testing.T) {
workflowOutputPathSnakeFlag := releaseWorkflowCmd.Flags().Lookup("workflow_output_path")
assert.NotNil(t, pathFlag)
assert.NotNil(t, workflowPathCamelFlag)
assert.NotNil(t, workflowPathFlag)
assert.NotNil(t, workflowPathSnakeFlag)
assert.NotNil(t, outputPathFlag)
@ -141,6 +151,7 @@ func TestBuildCmd_RunReleaseWorkflow_Good(t *testing.T) {
assert.NotNil(t, workflowOutputPathFlag)
assert.NotNil(t, workflowOutputPathSnakeFlag)
assert.NotEmpty(t, pathFlag.Usage)
assert.NotEmpty(t, workflowPathCamelFlag.Usage)
assert.NotEmpty(t, workflowPathFlag.Usage)
assert.NotEmpty(t, workflowPathSnakeFlag.Usage)
assert.NotEmpty(t, outputPathFlag.Usage)
@ -150,6 +161,7 @@ func TestBuildCmd_RunReleaseWorkflow_Good(t *testing.T) {
assert.NotEmpty(t, workflowOutputPathFlag.Usage)
assert.NotEmpty(t, workflowOutputPathSnakeFlag.Usage)
assert.NotEqual(t, pathFlag.Usage, outputFlag.Usage)
assert.Equal(t, pathFlag.Usage, workflowPathCamelFlag.Usage)
assert.Equal(t, pathFlag.Usage, workflowPathFlag.Usage)
assert.Equal(t, workflowPathFlag.Usage, workflowPathSnakeFlag.Usage)
assert.NotEqual(t, outputPathFlag.Usage, outputFlag.Usage)