Skip to content

Commit 7c4a543

Browse files
committed
Address review comments
1 parent 907ec3a commit 7c4a543

5 files changed

Lines changed: 50 additions & 16 deletions

File tree

cmd/commands/init.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ var initCmdFlags struct {
1414
// downloadPdscFiles forces all pdsc files from the public index to be downloaded
1515
downloadPdscFiles bool
1616

17+
// Includes deprecated packs
18+
includeDeprecated bool
19+
1720
// Reports encoded progress for files and download when used by other tools
1821
encodedProgress bool
1922

@@ -56,14 +59,15 @@ The index-url is mandatory. Ex "cpackget init --pack-root path/to/mypackroot htt
5659
return err
5760
}
5861

59-
err = installer.UpdatePublicIndex(indexPath, true, initCmdFlags.downloadPdscFiles, false, true, true, true, initCmdFlags.insecureSkipVerify, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
62+
err = installer.UpdatePublicIndex(indexPath, true, initCmdFlags.downloadPdscFiles, false, !initCmdFlags.includeDeprecated, true, true, initCmdFlags.insecureSkipVerify, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
6063
return err
6164
},
6265
}
6366

6467
func init() {
65-
InitCmd.Flags().BoolVarP(&initCmdFlags.downloadPdscFiles, "all-pdsc-files", "a", false, "downloads all the latest .pdsc files from the public index")
66-
InitCmd.Flags().BoolVarP(&initCmdFlags.encodedProgress, "encoded-progress", "E", false, "Reports encoded progress for files and download when used by other tools")
68+
InitCmd.Flags().BoolVarP(&initCmdFlags.downloadPdscFiles, "all-pdsc-files", "a", false, "downloads all the latest .pdsc files from the public index, except deprecated ones")
69+
InitCmd.Flags().BoolVarP(&initCmdFlags.includeDeprecated, "deprecated", "d", false, "includes deprecated .pdsc files when downloading")
70+
InitCmd.Flags().BoolVarP(&initCmdFlags.encodedProgress, "encoded-progress", "E", false, "reports encoded progress for files and download when used by other tools")
6771
InitCmd.Flags().BoolVar(&initCmdFlags.skipTouch, "skip-touch", false, "do not touch pack.idx")
6872
InitCmd.Flags().BoolVar(&initCmdFlags.insecureSkipVerify, "insecure-skip-verify", false, "skip verification of server's TLS certificate when downloading packs over HTTPS")
6973
}

cmd/commands/list.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ var ListCmd = &cobra.Command{
3333
Args: cobra.MaximumNArgs(0),
3434
PersistentPreRunE: configureInstaller,
3535
RunE: func(cmd *cobra.Command, args []string) error {
36-
if listCmdFlags.listDeprecated {
37-
listCmdFlags.listPublic = true
38-
}
3936
return installer.ListInstalledPacks(listCmdFlags.listCached, listCmdFlags.listPublic, listCmdFlags.listUpdates, listCmdFlags.listDeprecated, false, false, listCmdFlags.listFilter)
4037
},
4138
}

cmd/commands/update_index.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var updateIndexCmdFlags struct {
1717
// downloadPdscFiles forces all pdsc files from the public index to be downloaded
1818
downloadUpdatePdscFiles bool
1919

20+
// Includes deprecated packs
21+
includeDeprecated bool
22+
2023
// Reports encoded progress for files and download when used by other tools
2124
encodedProgress bool
2225

@@ -47,7 +50,7 @@ var UpdateIndexCmd = &cobra.Command{
4750
return err
4851
}
4952

50-
err = installer.UpdatePublicIndex("", updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, updateIndexCmdFlags.downloadUpdatePdscFiles, true, true, updateIndexCmdFlags.insecureSkipVerify, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
53+
err = installer.UpdatePublicIndex("", updateIndexCmdFlags.sparse, false, updateIndexCmdFlags.downloadUpdatePdscFiles, !updateIndexCmdFlags.includeDeprecated, true, true, updateIndexCmdFlags.insecureSkipVerify, viper.GetInt("concurrent-downloads"), viper.GetInt("timeout"))
5154
return err
5255
},
5356
}
@@ -59,8 +62,9 @@ By default it will also check if all PDSC files under .Web/ need update as well.
5962

6063
func init() {
6164
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.sparse, "sparse", "s", false, "avoid updating the pdsc files within .Web/ folder")
62-
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.downloadUpdatePdscFiles, "all-pdsc-files", "a", false, "updates/downloads all the latest .pdsc files from the public index")
63-
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.encodedProgress, "encoded-progress", "E", false, "Reports encoded progress for files and download when used by other tools")
65+
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.downloadUpdatePdscFiles, "all-pdsc-files", "a", false, "updates/downloads all the latest .pdsc files from the public index, except deprecated ones")
66+
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.includeDeprecated, "deprecated", "d", false, "includes deprecated .pdsc files when downloading")
67+
UpdateIndexCmd.Flags().BoolVarP(&updateIndexCmdFlags.encodedProgress, "encoded-progress", "E", false, "reports encoded progress for files and download when used by other tools")
6468
UpdateIndexCmd.Flags().BoolVar(&updateIndexCmdFlags.skipTouch, "skip-touch", false, "do not touch pack.idx")
6569
UpdateIndexCmd.Flags().BoolVar(&updateIndexCmdFlags.insecureSkipVerify, "insecure-skip-verify", false, "skip verification of server's TLS certificate when downloading packs over HTTPS")
6670
}

cmd/installer/root.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ func ListInstalledPacks(listCached, listPublic, listUpdates, listDeprecated, lis
12211221
return err
12221222
}
12231223
}
1224-
if listPublic {
1224+
if listPublic || listDeprecated {
12251225
if listFilter != "" {
12261226
log.Infof("Listing packs from the public index, filtering by %q", listFilter)
12271227
} else {
@@ -1242,12 +1242,10 @@ func ListInstalledPacks(listCached, listPublic, listUpdates, listDeprecated, lis
12421242
for _, pdscTag := range pdscTags {
12431243
isDeprecated := pdscTag.IsDeprecated()
12441244
// Filter by deprecated status:
1245-
// --deprecated: show only deprecated packs
1246-
// without --deprecated: hide deprecated packs
1247-
if listDeprecated && !isDeprecated {
1248-
continue
1249-
}
1250-
if !listDeprecated && isDeprecated {
1245+
// only --deprecated: show only deprecated packs
1246+
// only --public: hide deprecated packs
1247+
if (!listPublic && listDeprecated && !isDeprecated) ||
1248+
(listPublic && !listDeprecated && isDeprecated) {
12511249
continue
12521250
}
12531251
logMessage := pdscTag.YamlPackID()

cmd/installer/root_pack_list_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,37 @@ func TestListInstalledPacks(t *testing.T) {
318318
assert.Contains(stdout, "TheVendor::ActivePack@2.0.0")
319319
})
320320

321+
t.Run("test list public and deprecated shows both public and deprecated packs", func(t *testing.T) {
322+
localTestingDir := "test-list-public-and-deprecated"
323+
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
324+
installer.UnlockPackRoot()
325+
assert.Nil(installer.ReadIndexFiles())
326+
defer removePackRoot(localTestingDir)
327+
328+
assert.Nil(installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
329+
Vendor: "TheVendor",
330+
Name: "DeprecatedPack",
331+
Version: "1.0.0",
332+
Deprecated: "2020-01-01",
333+
}))
334+
assert.Nil(installer.Installation.PublicIndexXML.AddPdsc(xml.PdscTag{
335+
Vendor: "TheVendor",
336+
Name: "ActivePack",
337+
Version: "2.0.0",
338+
}))
339+
assert.Nil(installer.Installation.PublicIndexXML.Write())
340+
341+
var buf bytes.Buffer
342+
log.SetOutput(&buf)
343+
defer log.SetOutput(io.Discard)
344+
345+
// list --public --deprecated should show both public and deprecated packs
346+
assert.Nil(installer.ListInstalledPacks(!ListCached, ListPublic, !ListUpdates, ListDeprecated, !ListRequirements, true, ListFilter))
347+
stdout := buf.String()
348+
assert.Contains(stdout, "TheVendor::DeprecatedPack@1.0.0")
349+
assert.Contains(stdout, "TheVendor::ActivePack@2.0.0")
350+
})
351+
321352
t.Run("test list public deprecated with future date is not deprecated", func(t *testing.T) {
322353
localTestingDir := "test-list-deprecated-future-date"
323354
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))

0 commit comments

Comments
 (0)