Example #1
0
        private void CmdList(string[] args)
        {
            PolyListAssetsRequest req;

            if (args.Length > 0 && args[0] == "featured")
            {
                // Default list request (featured).
                req = PolyListAssetsRequest.Featured();
            }
            else if (args.Length > 0 && args[0] == "latest")
            {
                // Default list request (latest).
                req = PolyListAssetsRequest.Latest();
            }
            else
            {
                // Custom list request.
                req = new PolyListAssetsRequest();
            }
            // Mutate the request according to parameters.
            req.category      = GetEnumOpt(args, "-c", req.category);
            req.curated       = HasOpt(args, "-k") ? true : req.curated;
            req.keywords      = GetOpt(args, "-s", req.keywords);
            req.maxComplexity = GetEnumOpt(args, "--maxc", req.maxComplexity);
            req.orderBy       = GetEnumOpt(args, "-o", req.orderBy);
            req.pageSize      = GetIntOpt(args, "-p", req.pageSize);
            req.pageToken     = GetOpt(args, "--pt", req.pageToken);
            // FormatFilter is weird because it's nullable, so we have to test before trying to parse:
            if (HasOpt(args, "-f"))
            {
                req.formatFilter = GetEnumOpt(args, "-f", PolyFormatFilter.BLOCKS /* not used */);
            }

            if (HasOpt(args, "--dry"))
            {
                // Dry run mode.
                PrintLn(req.ToString());
                return;
            }

            // Send the request.
            hasRunListCommand = true;
            PrintLn("Sending list request... Please wait.");
            PolyApi.ListAssets(req, (PolyStatusOr <PolyListAssetsResult> res) => {
                if (!res.Ok)
                {
                    PrintLn("Request ERROR: " + res.Status);
                    return;
                }
                currentResults = res.Value.assets;
                CmdShow(new string[] {});
            });
        }