@@ -23,12 +23,14 @@ func AlternativeDistributionPackageVersionsCommand() *ffcli.Command {
2323 LongHelp : `Manage alternative distribution package versions.
2424
2525Examples:
26+ asc alternative-distribution packages versions list --package-id "PACKAGE_ID"
2627 asc alternative-distribution packages versions get --version-id "VERSION_ID"
2728 asc alternative-distribution packages versions deltas --version-id "VERSION_ID"
2829 asc alternative-distribution packages versions variants --version-id "VERSION_ID"` ,
2930 FlagSet : fs ,
3031 UsageFunc : DefaultUsageFunc ,
3132 Subcommands : []* ffcli.Command {
33+ AlternativeDistributionPackageVersionsListCommand (),
3234 AlternativeDistributionPackageVersionsGetCommand (),
3335 AlternativeDistributionPackageVersionsDeltasCommand (),
3436 AlternativeDistributionPackageVersionsVariantsCommand (),
@@ -39,6 +41,81 @@ Examples:
3941 }
4042}
4143
44+ // AlternativeDistributionPackageVersionsListCommand returns the package versions list subcommand.
45+ func AlternativeDistributionPackageVersionsListCommand () * ffcli.Command {
46+ fs := flag .NewFlagSet ("list" , flag .ExitOnError )
47+
48+ packageID := fs .String ("package-id" , "" , "Alternative distribution package ID" )
49+ limit := fs .Int ("limit" , 0 , "Maximum results per page (1-200)" )
50+ next := fs .String ("next" , "" , "Fetch next page using a links.next URL" )
51+ paginate := fs .Bool ("paginate" , false , "Automatically fetch all pages (aggregate results)" )
52+ output := fs .String ("output" , "json" , "Output format: json (default), table, markdown" )
53+ pretty := fs .Bool ("pretty" , false , "Pretty-print JSON output" )
54+
55+ return & ffcli.Command {
56+ Name : "list" ,
57+ ShortUsage : "asc alternative-distribution packages versions list --package-id \" PACKAGE_ID\" [flags]" ,
58+ ShortHelp : "List alternative distribution package versions." ,
59+ LongHelp : `List alternative distribution package versions.
60+
61+ Examples:
62+ asc alternative-distribution packages versions list --package-id "PACKAGE_ID"
63+ asc alternative-distribution packages versions list --package-id "PACKAGE_ID" --paginate` ,
64+ FlagSet : fs ,
65+ UsageFunc : DefaultUsageFunc ,
66+ Exec : func (ctx context.Context , args []string ) error {
67+ trimmedID := strings .TrimSpace (* packageID )
68+ if trimmedID == "" {
69+ fmt .Fprintln (os .Stderr , "Error: --package-id is required" )
70+ return flag .ErrHelp
71+ }
72+ if * limit != 0 && (* limit < 1 || * limit > alternativeDistributionMaxLimit ) {
73+ return fmt .Errorf ("alternative-distribution packages versions list: --limit must be between 1 and %d" , alternativeDistributionMaxLimit )
74+ }
75+ if err := validateNextURL (* next ); err != nil {
76+ return fmt .Errorf ("alternative-distribution packages versions list: %w" , err )
77+ }
78+
79+ client , err := getASCClient ()
80+ if err != nil {
81+ return fmt .Errorf ("alternative-distribution packages versions list: %w" , err )
82+ }
83+
84+ requestCtx , cancel := contextWithTimeout (ctx )
85+ defer cancel ()
86+
87+ opts := []asc.AlternativeDistributionPackageVersionsOption {
88+ asc .WithAlternativeDistributionPackageVersionsLimit (* limit ),
89+ asc .WithAlternativeDistributionPackageVersionsNextURL (* next ),
90+ }
91+
92+ if * paginate {
93+ paginateOpts := append (opts , asc .WithAlternativeDistributionPackageVersionsLimit (alternativeDistributionMaxLimit ))
94+ firstPage , err := client .GetAlternativeDistributionPackageVersions (requestCtx , trimmedID , paginateOpts ... )
95+ if err != nil {
96+ return fmt .Errorf ("alternative-distribution packages versions list: failed to fetch: %w" , err )
97+ }
98+
99+ resp , err := asc .PaginateAll (requestCtx , firstPage , func (ctx context.Context , nextURL string ) (asc.PaginatedResponse , error ) {
100+ return client .GetAlternativeDistributionPackageVersions (ctx , trimmedID , asc .WithAlternativeDistributionPackageVersionsNextURL (nextURL ))
101+ })
102+ if err != nil {
103+ return fmt .Errorf ("alternative-distribution packages versions list: %w" , err )
104+ }
105+
106+ return printOutput (resp , * output , * pretty )
107+ }
108+
109+ resp , err := client .GetAlternativeDistributionPackageVersions (requestCtx , trimmedID , opts ... )
110+ if err != nil {
111+ return fmt .Errorf ("alternative-distribution packages versions list: failed to fetch: %w" , err )
112+ }
113+
114+ return printOutput (resp , * output , * pretty )
115+ },
116+ }
117+ }
118+
42119// AlternativeDistributionPackageVersionsGetCommand returns the package versions get subcommand.
43120func AlternativeDistributionPackageVersionsGetCommand () * ffcli.Command {
44121 fs := flag .NewFlagSet ("get" , flag .ExitOnError )
0 commit comments