mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
# Overview This pull request resolves #31165, implementing command-line tooling to migrate GitOps YAML files following the [changes introduced in the upcoming 4.74 release](https://github.com/fleetdm/fleet/pull/32237/files#diff-8769f6e90e8bdf15faad8f390fdf3ffb6fd2238b7d6087d83518c21464109119R7). Aligning with the recommended steps in the `README`; [this is an example of the first step](https://github.com/Illbjorn/fleet/pull/3/files) (`gitops-migrate format`) and [this is an example of the second step](https://github.com/Illbjorn/fleet/pull/4/files) (`gitops-migrate migrate`). --------- Signed-off-by: Illbjorn <am@hades.so> Co-authored-by: Ian Littman <iansltx@gmail.com>
41 lines
937 B
Go
41 lines
937 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
func cmdExec(ctx context.Context, args Args) error {
|
|
// Check for the ['--help', '-h'] flag.
|
|
if args.Help {
|
|
showUsageAndExit(0, "")
|
|
}
|
|
|
|
// Make sure we have a command past this point.
|
|
if len(args.Commands) == 0 {
|
|
showUsageAndExit(2, "Received no command.")
|
|
}
|
|
|
|
// Slice off the first command.
|
|
//
|
|
// If we decide to do nested subcommands in the future this will make it super
|
|
// straightforward to implement the branching.
|
|
cmd := args.Commands[0]
|
|
args.Commands = args.Commands[1:]
|
|
|
|
switch strings.ToLower(cmd) {
|
|
case cmdUsage, cmdHelp:
|
|
return cmdUsageExec(ctx, args)
|
|
case cmdFormat:
|
|
return cmdFormatExec(ctx, args)
|
|
case cmdMigrate:
|
|
return cmdMigrateExec(ctx, args)
|
|
case cmdBackup:
|
|
return cmdBackupExec(ctx, args)
|
|
case cmdRestore:
|
|
return cmdRestoreExec(ctx, args)
|
|
default:
|
|
showUsageAndExit(2, "Received unknown command: %s.", cmd)
|
|
panic("impossible")
|
|
}
|
|
}
|