Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions cmd/admin/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"crypto/rsa"
"crypto/tls"
"fmt"
Expand Down Expand Up @@ -31,7 +32,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// Constants for the service
Expand Down Expand Up @@ -93,7 +94,7 @@ var (
adminUsers *users.UserManager
tagsmgr *tags.TagManager
carvers3 *carves.CarverS3
app *cli.App
app *cli.Command
flags []cli.Flag
flagParams config.ServiceFlagParams
// FIXME this is nasty and should not be a global but here we are
Expand Down Expand Up @@ -618,7 +619,7 @@ func osctrlAdminService() {
}

// Action to run when no flags are provided to run checks and prepare data
func cliAction(c *cli.Context) error {
func cliAction(ctx context.Context, cmd *cli.Command) error {
// Load configuration if external JSON config file is used
if flagParams.ConfigFlag {
flagParams.ConfigValues, err = loadConfiguration(flagParams.ServiceConfigFile, config.ServiceAdmin)
Expand Down Expand Up @@ -703,44 +704,45 @@ func initializeLoggers(cfg config.JSONConfigurationService) {

func main() {
// Initiate CLI and parse arguments
app = cli.NewApp()
app.Name = serviceName
app.Usage = appDescription
app.Version = buildVersion
app.Description = appDescription
app.Flags = flags
// Customize version output (supports `--version` and `version` command)
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
}
// Add -v alias to the global --version flag
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version information",
}
// Define this command for help to exit when help flag is passed
app.Commands = []*cli.Command{
{
Name: "help",
Action: func(c *cli.Context) error {
cli.ShowAppHelpAndExit(c, 0)
app = &cli.Command{
Name: serviceName,
Usage: appDescription,
Version: buildVersion,
Description: appDescription,
Flags: append(flags, &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version information",
Action: func(ctx context.Context, cmd *cli.Command, b bool) error {
if b {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
os.Exit(0)
}
return nil
},
}),
HideVersion: true,
Commands: []*cli.Command{
{
Name: "help",
Action: func(ctx context.Context, cmd *cli.Command) error {
cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0)
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using cmd.Name (which is "help") as the command name parameter is incorrect. This should show the app-level help. Change to cli.ShowCommandHelpAndExit(ctx, cmd.Parent, \"\", 0) or use an empty string for the command name.

Suggested change
cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0)
cli.ShowCommandHelpAndExit(ctx, cmd.Parent, "", 0)

Copilot uses AI. Check for mistakes.
return nil
},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
if err := cliAction(ctx, cmd); err != nil {
return err
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Service starts!
osctrlAdminService()
return nil
},
}
// Start service only for default action; version/help won't trigger this
app.Action = func(c *cli.Context) error {
if err := cliAction(c); err != nil {
return err
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Service starts!
osctrlAdminService()
return nil
}
if err := app.Run(os.Args); err != nil {
if err := app.Run(context.Background(), os.Args); err != nil {
fmt.Printf("app.Run error: %s", err.Error())
os.Exit(1)
}
Expand Down
76 changes: 39 additions & 37 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"crypto/tls"
"fmt"
"net/http"
Expand All @@ -26,7 +27,7 @@ import (
"github.com/jmpsec/osctrl/pkg/version"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -102,7 +103,7 @@ var (
queriesmgr *queries.Queries
filecarves *carves.Carves
handlersApi *handlers.HandlersApi
app *cli.App
app *cli.Command
flags []cli.Flag
flagParams config.ServiceFlagParams
auditLog *auditlog.AuditLogManager
Expand Down Expand Up @@ -438,7 +439,7 @@ func osctrlAPIService() {
}

// Action to run when no flags are provided to run checks and prepare data
func cliAction(c *cli.Context) error {
func cliAction(ctx context.Context, cmd *cli.Command) error {
// Load configuration if external JSON config file is used
if flagParams.ConfigFlag {
flagParams.ConfigValues, err = loadConfiguration(flagParams.ServiceConfigFile, config.ServiceAPI)
Expand Down Expand Up @@ -500,44 +501,45 @@ func initializeLoggers(cfg config.JSONConfigurationService) {

func main() {
// Initiate CLI and parse arguments
app = cli.NewApp()
app.Name = serviceName
app.Usage = appDescription
app.Version = buildVersion
app.Description = appDescription
app.Flags = flags
// Customize version output (supports `--version` and `version` command)
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
}
// Add -v alias to the global --version flag
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version information",
}
// Define this command for help to exit when help flag is passed
app.Commands = []*cli.Command{
{
Name: "help",
Action: func(c *cli.Context) error {
cli.ShowAppHelpAndExit(c, 0)
app = &cli.Command{
Name: serviceName,
Usage: appDescription,
Version: buildVersion,
Description: appDescription,
Flags: append(flags, &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version information",
Action: func(ctx context.Context, cmd *cli.Command, b bool) error {
if b {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
os.Exit(0)
}
return nil
},
}),
HideVersion: true,
Commands: []*cli.Command{
{
Name: "help",
Action: func(ctx context.Context, cmd *cli.Command) error {
cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0)
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using cmd.Name (which is "help") as the command name parameter is incorrect. This should show the app-level help, not help for the help command itself. Change to cli.ShowCommandHelpAndExit(ctx, cmd.Parent, \"\", 0) or use an empty string for the command name.

Suggested change
cli.ShowCommandHelpAndExit(ctx, cmd, cmd.Name, 0)
cli.ShowCommandHelpAndExit(ctx, cmd, "", 0)

Copilot uses AI. Check for mistakes.
return nil
},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
if err := cliAction(ctx, cmd); err != nil {
return err
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Run the service
osctrlAPIService()
return nil
},
}
// Start service only for default action; version/help won't trigger this
app.Action = func(c *cli.Context) error {
if err := cliAction(c); err != nil {
return err
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Run the service
osctrlAPIService()
return nil
}
if err := app.Run(os.Args); err != nil {
if err := app.Run(context.Background(), os.Args); err != nil {
fmt.Printf("app.Run error: %s", err.Error())
os.Exit(1)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/cli/audit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/csv"
"encoding/json"
"fmt"
Expand All @@ -9,7 +10,7 @@ import (
"github.com/jmpsec/osctrl/pkg/auditlog"
"github.com/jmpsec/osctrl/pkg/environments"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// Helper function to convert a slice of audit logs entries into the data expected for output
Expand Down Expand Up @@ -84,7 +85,7 @@ func helperAuditLogs(als []auditlog.AuditLog, m environments.MapEnvByID) error {
return nil
}

func auditLogs(c *cli.Context) error {
func auditLogs(ctx context.Context, cmd *cli.Command) error {
var als []auditlog.AuditLog
var m environments.MapEnvByID
if dbFlag {
Expand Down
Loading
Loading