added workdir flag and env var

This commit is contained in:
Zack Brady
2026-08-17 23:35:51 -04:00
parent e120d5e58f
commit 72f3727895
4 changed files with 15 additions and 2 deletions
+4 -2
View File
@@ -163,12 +163,14 @@ func SyncCmd(ctx context.Context, o *flags.SyncOpts, s *store.Layout, rso *flags
if err != nil {
return fmt.Errorf("failed to fetch product manifest for [%s]: %w", productName, err)
}
err = ExtractCmd(ctx, &flags.ExtractOpts{StoreRootOpts: o.StoreRootOpts, DestinationDir: tempDir}, s, fmt.Sprintf("hauler/%s-manifest.yaml:%s", parts[0], tag))
// The manifest is output for the user, so it goes to workDir, not tempDir (removed when sync returns).
workDir := flags.ResolveWorkDir(ro)
err = ExtractCmd(ctx, &flags.ExtractOpts{StoreRootOpts: o.StoreRootOpts, DestinationDir: workDir}, s, fmt.Sprintf("hauler/%s-manifest.yaml:%s", parts[0], tag))
if err != nil {
return err
}
fileName := fmt.Sprintf("%s-manifest.yaml", parts[0])
fi, err := os.Open(filepath.Join(tempDir, fileName))
fi, err := os.Open(filepath.Join(workDir, fileName))
if err != nil {
return err
}
+2
View File
@@ -7,6 +7,7 @@ type CliRootOpts struct {
HaulerDir string
IgnoreErrors bool
AuditLevel string
WorkDir string
}
func AddRootFlags(cmd *cobra.Command, ro *CliRootOpts) {
@@ -16,4 +17,5 @@ func AddRootFlags(cmd *cobra.Command, ro *CliRootOpts) {
pf.StringVarP(&ro.HaulerDir, "haulerdir", "d", "", "Set the location of the hauler directory (default $HOME/.hauler)")
pf.BoolVar(&ro.IgnoreErrors, "ignore-errors", false, "Warn and continue instead of failing on errors, including storing images that failed verification (defaults false)")
pf.StringVar(&ro.AuditLevel, "audit-level", "", "Set the audit logging level (none, standard, verbose) (defaults standard)")
pf.StringVarP(&ro.WorkDir, "work-dir", "w", "", "(Optional) Set the directory for output that commands would otherwise write to the current directory (default: current directory)")
}
+8
View File
@@ -144,3 +144,11 @@ func resolveHaulerDir(ro *CliRootOpts) string {
home, _ := os.UserHomeDir()
return filepath.Join(home, consts.DefaultHaulerDirName)
}
// ResolveWorkDir returns the configured output dir, or "" to mean the current directory (legacy behavior).
func ResolveWorkDir(ro *CliRootOpts) string {
if ro != nil && ro.WorkDir != "" {
return ro.WorkDir
}
return os.Getenv(consts.HaulerWorkDir)
}
+1
View File
@@ -95,6 +95,7 @@ const (
// environment variables
HaulerDir = "HAULER_DIR"
HaulerTempDir = "HAULER_TEMP_DIR"
HaulerWorkDir = "HAULER_WORK_DIR"
HaulerStoreDir = "HAULER_STORE_DIR"
HaulerIgnoreErrors = "HAULER_IGNORE_ERRORS"
HaulerRetries = "HAULER_RETRIES"