Skip to content

Commit

Permalink
refactor: remove legacy v1 to v2 migration feature (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h authored Apr 30, 2024
1 parent ef58c7a commit 77ba285
Show file tree
Hide file tree
Showing 44 changed files with 11 additions and 6,679 deletions.
42 changes: 0 additions & 42 deletions cmd/templ/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/a-h/templ/cmd/templ/fmtcmd"
"github.com/a-h/templ/cmd/templ/generatecmd"
"github.com/a-h/templ/cmd/templ/lspcmd"
"github.com/a-h/templ/cmd/templ/migratecmd"
"github.com/fatih/color"
)

Expand All @@ -34,7 +33,6 @@ commands:
generate Generates Go code from templ files
fmt Formats templ files
lsp Starts a language server for templ files
migrate Migrates v1 templ files to v2 format
version Prints the version
`

Expand All @@ -46,8 +44,6 @@ func run(w io.Writer, args []string) (code int) {
switch args[1] {
case "generate":
return generateCmd(w, args[2:])
case "migrate":
return migrateCmd(w, args[2:])
case "fmt":
return fmtCmd(w, args[2:])
case "lsp":
Expand Down Expand Up @@ -189,44 +185,6 @@ func generateCmd(w io.Writer, args []string) (code int) {
return 0
}

const migrateUsageText = `usage: templ migrate [<args> ...]
Migrates v1 templ files to v2 format.
Args:
-f string
Optionally migrate a single file, e.g. -f header.templ
-help
Print help and exit.
-path string
Migrates code for all files in path.
`

func migrateCmd(w io.Writer, args []string) (code int) {
cmd := flag.NewFlagSet("migrate", flag.ExitOnError)
cmd.SetOutput(w)
fileName := cmd.String("f", "", "")
path := cmd.String("path", "", "")
helpFlag := cmd.Bool("help", false, "")
cmd.Usage = func() {
fmt.Fprint(w, migrateUsageText)
}
err := cmd.Parse(args)
if err != nil || *helpFlag || (*path == "" && *fileName == "") {
cmd.Usage()
return
}
err = migratecmd.Run(w, migratecmd.Arguments{
FileName: *fileName,
Path: *path,
})
if err != nil {
fmt.Fprintln(w, err.Error())
return 1
}
return 0
}

const fmtUsageText = `usage: templ fmt [<args> ...]
Format all files in directory:
Expand Down
12 changes: 0 additions & 12 deletions cmd/templ/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ func TestMain(t *testing.T) {
expected: templ.Version() + "\n",
expectedCode: 0,
},
{
name: `"templ migrate" prints usage`,
args: []string{"templ", "migrate"},
expected: migrateUsageText,
expectedCode: 0,
},
{
name: `"templ migrate --help" prints usage`,
args: []string{"templ", "migrate", "--help"},
expected: migrateUsageText,
expectedCode: 0,
},
{
name: `"templ fmt --help" prints usage`,
args: []string{"templ", "fmt", "--help"},
Expand Down
Loading

0 comments on commit 77ba285

Please sign in to comment.