@@ -30,6 +30,7 @@ import (
3030 "perfspect/cmd/report"
3131 "perfspect/cmd/telemetry"
3232 "perfspect/internal/app"
33+ "perfspect/internal/script"
3334 "perfspect/internal/util"
3435
3536 "github.com/pkg/errors"
@@ -114,6 +115,7 @@ Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
114115 rootCmd .AddCommand (config .Cmd )
115116 rootCmd .AddGroup ([]* cobra.Group {{ID : "other" , Title : "Other Commands:" }}... )
116117 rootCmd .AddCommand (updateCmd )
118+ rootCmd .AddCommand (extractCmd )
117119 // Global (persistent) flags
118120 rootCmd .PersistentFlags ().BoolVar (& flagDebug , app .FlagDebugName , false , "enable debug logging and retain temporary directories" )
119121 rootCmd .PersistentFlags ().BoolVar (& flagSyslog , app .FlagSyslogName , false , "write logs to syslog instead of a file" )
@@ -489,6 +491,29 @@ func getLatestManifest() (manifest, error) {
489491 return latestManifest , nil
490492}
491493
494+ // define the extract command
495+ const (
496+ extractCommandName = "extract"
497+ )
498+
499+ var extractCmd = & cobra.Command {
500+ GroupID : "other" ,
501+ Use : extractCommandName ,
502+ Short : "Extract the embedded resources (for developers)" ,
503+ RunE : func (cmd * cobra.Command , args []string ) error {
504+ appContext := cmd .Parent ().Context ().Value (app.Context {}).(app.Context )
505+ // extract the internal/script module's embedded resources
506+ err := util .ExtractAllResources (script .Resources , appContext .OutputDir )
507+ if err != nil {
508+ slog .Error ("Failed to extract script resources" , slog .String ("error" , err .Error ()))
509+ fmt .Printf ("Error: failed to extract script resources: %v\n " , err )
510+ return err
511+ }
512+ fmt .Printf ("Extracted script resources to %s\n " , appContext .OutputDir )
513+ return nil
514+ },
515+ }
516+
492517// SyslogHandler is a slog.Handler that logs to syslog.
493518type SyslogHandler struct {
494519 writer * syslog.Writer
0 commit comments