From 98c0012bb96110c2fc5a45dc3a780bf5114c42d9 Mon Sep 17 00:00:00 2001 From: Daniel McIlvaney Date: Fri, 22 May 2026 15:20:41 -0700 Subject: [PATCH] feat: Add flag to source prep to skip downloading source tars --- .../reference/cli/azldev_component_prepare-sources.md | 1 + internal/app/azldev/cmds/component/preparesources.go | 8 ++++++++ internal/app/azldev/cmds/component/preparesources_test.go | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/docs/user/reference/cli/azldev_component_prepare-sources.md b/docs/user/reference/cli/azldev_component_prepare-sources.md index 9e22b5c5..590286e7 100644 --- a/docs/user/reference/cli/azldev_component_prepare-sources.md +++ b/docs/user/reference/cli/azldev_component_prepare-sources.md @@ -41,6 +41,7 @@ azldev component prepare-sources [flags] -o, --output-dir string output directory --skip-lock-validation skip lock file consistency checks --skip-overlays skip applying overlays to prepared sources + --skip-sources skip downloading fetched sources when preparing the package (useful to extract dist-git metadata when source files are not needed) -s, --spec-path stringArray Spec path --without-git Disable dist-git repository creation (enabled by default) ``` diff --git a/internal/app/azldev/cmds/component/preparesources.go b/internal/app/azldev/cmds/component/preparesources.go index 1a40b2f1..2f0ffcaa 100644 --- a/internal/app/azldev/cmds/component/preparesources.go +++ b/internal/app/azldev/cmds/component/preparesources.go @@ -24,6 +24,7 @@ type PrepareSourcesOptions struct { WithoutGitRepo bool Force bool AllowNoHashes bool + SkipSources bool } func prepareOnAppInit(_ *azldev.App, sourceCmd *cobra.Command) { @@ -73,6 +74,9 @@ Only one component may be selected at a time.`, cmd.Flags().BoolVar(&options.Force, "force", false, "delete and recreate the output directory if it already exists") cmd.Flags().BoolVar(&options.AllowNoHashes, "allow-no-hashes", false, "compute missing hashes by downloading source files from their origin") + cmd.Flags().BoolVar(&options.SkipSources, "skip-sources", false, + "skip downloading fetched sources when preparing the package (useful to extract "+ + "dist-git metadata when source files are not needed)") return cmd } @@ -138,6 +142,10 @@ func PrepareComponentSources(env *azldev.Env, options *PrepareSourcesOptions) er preparerOpts = append(preparerOpts, sources.WithAllowNoHashes()) } + if options.SkipSources { + preparerOpts = append(preparerOpts, sources.WithSkipLookaside()) + } + preparer, err := sources.NewPreparer(sourceManager, env.FS(), env, env, preparerOpts...) if err != nil { return fmt.Errorf("failed to create source preparer:\n%w", err) diff --git a/internal/app/azldev/cmds/component/preparesources_test.go b/internal/app/azldev/cmds/component/preparesources_test.go index 720b0941..36344aad 100644 --- a/internal/app/azldev/cmds/component/preparesources_test.go +++ b/internal/app/azldev/cmds/component/preparesources_test.go @@ -34,6 +34,11 @@ func TestNewPrepareSourcesCmd(t *testing.T) { assert.Equal(t, "false", withoutGitFlag.DefValue, "dist-git flow should be enabled by default") assert.Contains(t, withoutGitFlag.Usage, "dist-git") + skipSourcesFlag := cmd.Flags().Lookup("skip-sources") + require.NotNil(t, skipSourcesFlag, "--skip-sources flag should be registered") + assert.Equal(t, "false", skipSourcesFlag.DefValue) + assert.Contains(t, skipSourcesFlag.Usage, "skip downloading") + // Legacy --with-git flag must NOT exist. withGitFlag := cmd.Flags().Lookup("with-git") assert.Nil(t, withGitFlag, "--with-git flag must not be registered")