mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
155 lines
3.5 KiB
Go
155 lines
3.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/hanzoai/git/modules/private"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
func newManagerCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "manager",
|
|
Usage: "Manage the running Hanzo Git process",
|
|
Description: "This is a command for managing the running Hanzo Git process",
|
|
Commands: []*cli.Command{
|
|
newShutdownCommand(),
|
|
newRestartCommand(),
|
|
newReloadTemplatesCommand(),
|
|
newFlushQueuesCommand(),
|
|
newLoggingCommand(),
|
|
newProcessesCommand(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func newShutdownCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "shutdown",
|
|
Usage: "Gracefully shutdown the running process",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Action: runShutdown,
|
|
}
|
|
}
|
|
|
|
func newRestartCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "restart",
|
|
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Action: runRestart,
|
|
}
|
|
}
|
|
|
|
func newReloadTemplatesCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "reload-templates",
|
|
Usage: "Reload template files in the running process",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Action: runReloadTemplates,
|
|
}
|
|
}
|
|
|
|
func newFlushQueuesCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "flush-queues",
|
|
Usage: "Flush queues in the running process",
|
|
Action: runFlushQueues,
|
|
Flags: []cli.Flag{
|
|
&cli.DurationFlag{
|
|
Name: "timeout",
|
|
Value: 60 * time.Second,
|
|
Usage: "Timeout for the flushing process",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "non-blocking",
|
|
Usage: "Set to true to not wait for flush to complete before returning",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func newProcessesCommand() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "processes",
|
|
Usage: "Display running processes within the current process",
|
|
Action: runProcesses,
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "flat",
|
|
Usage: "Show processes as flat table rather than as tree",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "no-system",
|
|
Usage: "Do not show system processes",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "stacktraces",
|
|
Usage: "Show stacktraces",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "json",
|
|
Usage: "Output as json",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "cancel",
|
|
Usage: "Process PID to cancel. (Only available for non-system processes.)",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func runShutdown(ctx context.Context, c *cli.Command) error {
|
|
setup(ctx, c.Bool("debug"))
|
|
extra := private.Shutdown(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runRestart(ctx context.Context, c *cli.Command) error {
|
|
setup(ctx, c.Bool("debug"))
|
|
extra := private.Restart(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runReloadTemplates(ctx context.Context, c *cli.Command) error {
|
|
setup(ctx, c.Bool("debug"))
|
|
extra := private.ReloadTemplates(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runFlushQueues(ctx context.Context, c *cli.Command) error {
|
|
setup(ctx, c.Bool("debug"))
|
|
extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runProcesses(ctx context.Context, c *cli.Command) error {
|
|
setup(ctx, c.Bool("debug"))
|
|
extra := private.Processes(ctx, os.Stdout, c.Bool("flat"), c.Bool("no-system"), c.Bool("stacktraces"), c.Bool("json"), c.String("cancel"))
|
|
return handleCliResponseExtra(extra)
|
|
}
|