Skip to content

Commit

Permalink
cmd/cue: add refactor imports command
Browse files Browse the repository at this point in the history
This will make it easier to migrate between module
locations and major versions.

It's experimental for now.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Icc86a3cc852d20ddecf19df143d2614ecd065dc0
Dispatch-Trailer: {"type":"trybot","CL":1207988,"patchset":9,"ref":"refs/changes/88/1207988/9","targetBranch":"master"}
  • Loading branch information
rogpeppe authored and cueckoo committed Jan 30, 2025
1 parent 5a10b5c commit 828d28d
Show file tree
Hide file tree
Showing 9 changed files with 939 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/cue/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import (
const (
flagAll flagName = "all"
flagAllErrors flagName = "all-errors"
flagAllMajor flagName = "all-major"
flagCheck flagName = "check"
flagDiff flagName = "diff"
flagDryRun flagName = "dry-run"
flagEscape flagName = "escape"
flagExact flagName = "exact"
flagExpression flagName = "expression"
flagExt flagName = "ext"
flagFiles flagName = "files"
flagForce flagName = "force"
flagGlob flagName = "name"
flagIdent flagName = "ident"
flagIgnore flagName = "ignore"
flagInject flagName = "inject"
flagInjectVars flagName = "inject-vars"
Expand All @@ -53,6 +56,7 @@ const (
flagSource flagName = "source"
flagStrict flagName = "strict"
flagTrace flagName = "trace"
flagUpdateIdent flagName = "update-ident"
flagVerbose flagName = "verbose"
flagWithContext flagName = "with-context"

Expand Down
48 changes: 48 additions & 0 deletions cmd/cue/cmd/refactor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 CUE Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

func newRefactorCmd(c *Command) *cobra.Command {
cmd := &cobra.Command{
// Experimental so far.
Hidden: true,

Use: "refactor <cmd> [arguments]",
Short: "refactor and rewrite CUE code",
Long: `
This command groups together commands relating
to altering code within the current CUE module.
`[1:],
RunE: mkRunE(c, func(cmd *Command, args []string) error {
stderr := cmd.Stderr()
if len(args) == 0 {
fmt.Fprintln(stderr, "refactor must be run as one of its subcommands")
} else {
fmt.Fprintf(stderr, "refactor must be run as one of its subcommands: unknown subcommand %q\n", args[0])
}
fmt.Fprintln(stderr, "Run 'cue help refactor' for known subcommands.")
return ErrPrintedError
}),
}

cmd.AddCommand(newRefactorImportsCmd(c))
return cmd
}
Loading

0 comments on commit 828d28d

Please sign in to comment.