Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(podman): add podman completion spec #2158

Merged
merged 6 commits into from
Dec 4, 2023
Merged

feat(podman): add podman completion spec #2158

merged 6 commits into from
Dec 4, 2023

Conversation

diegofcornejo
Copy link
Contributor

In addition to the specs for Podman, 'pretty-quick --staged' was removed from package.json. It was not possible to run the pre-commit because it was giving the error '_prettier.resolveConfig.sync is not a function', which is documented at prettier/pretty-quick#164. The package has not been updated for more than 2 years.

@withfig-bot
Copy link
Collaborator

withfig-bot commented Nov 2, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@withfig-bot
Copy link
Collaborator

withfig-bot commented Nov 2, 2023

Overview

src/podman.ts:

Info:

Single Functions:

postProcess:

 function (out) {
      return out
        .split("\n")
        .map((line) => JSON.parse(line))
        .map((i) => ({
          name: `${i.Id}`,
          displayName: `${i.repository} - ${i.Id}`,
          icon: "fig://icon?type=docker",
        }));
    }

postProcess:

 function (out) {
      return out
        .split("\n")
        .map((line) => JSON.parse(line))
        .map((i) => ({
          name: i.repository,
          displayName: `${i.repository} - ${i.Id}`,
          icon: "fig://icon?type=docker",
        }));
    }

script:

 function (context) {
      if (context[context.length - 1] === "") return undefined;
      const searchTerm = context[context.length - 1];
      return ["podman", "search", searchTerm, "--format", "{{ json . }}"];
    }

postProcess:

 function (out) {
      return out
        .split("\n")
        .map((line) => JSON.parse(line))
        .map((i) => ({
          name: `${i.Name}`,
          icon: "fig://icon?type=docker",
        }));
    }

trigger:

 function () {
      return true;
    }

postProcess:

 function (out) {
      return out
        .split("\n")
        .map((line) => JSON.parse(line))
        .map((i) => ({
          name: i.Name,
          icon: "fig://icon?type=docker",
        }));
    }

trigger:

 function () {
              return true;
            }

script:

 function (context) {
              let fileFlagIndex, dockerfilePath;
              if (context.includes("-f")) {
                fileFlagIndex = context.indexOf("-f");
                dockerfilePath = context[fileFlagIndex + 1];
              } else if (context.includes("--file")) {
                fileFlagIndex = context.indexOf("--file");
                dockerfilePath = context[fileFlagIndex + 1];
              } else {
                dockerfilePath = "Dockerfile";
              }

              return ["grep", "-iE", "FROM.*AS", dockerfilePath];
            }

postProcess:

 function (out) {
              // This just searches the Dockerfile for the alias name after AS,
              // and due to the grep above, will only match lines where FROM and AS
              // are on the same line. This could certainly be made more robust
              // down the line.
              const imageNameRegexp = /(?:[aA][sS]\s+)([\w:.-]+)/;
              return out
                .split("\n")
                .map((i) => {
                  const result = imageNameRegexp.exec(i);
                  if (result) {
                    return {
                      name: result[1],
                    };
                  }
                })
                .filter((i) => i !== undefined);
            }

postProcess:

 function (out) {
            return out.split("\n").map((image) => {
              const [repo, size, tag, id] = image.split(" ");
              return {
                name: repo,
                description: `${id}@${tag} - ${size}`,
                icon: "fig://icon?type=docker",
              };
            });
          }

postProcess:

 function (out) {
              const allLines = out.split("\n").map((line) => JSON.parse(line));
              return allLines.map((i) => ({
                name: i.Id,
                displayName: `[con] ${i.Id} (${i.Image})`,
              }));
            }

postProcess:

 function (out) {
              const allLines = out.split("\n").map((line) => JSON.parse(line));
              return allLines.map((i) => {
                let displayName;
                if (i.repository === "\u003cnone\u003e") {
                  displayName = i.Id;
                } else {
                  displayName = i.repository;
                  if (i.Tag !== "\u003cnone\u003e") {
                    displayName += `:${i.tag}`;
                  }
                }

                return {
                  name: i.ID,
                  displayName: `[img] ${displayName}`,
                };
              });
            }

postProcess:

 function (out) {
              const allLines = out.split("\n").map((line) => JSON.parse(line));
              return allLines.map((i) => ({
                name: i.Name,
                displayName: `[vol] ${i.Name}`,
              }));
            }

@withfig-bot
Copy link
Collaborator

Hello @diegofcornejo,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments include the args property (args: {})?
  • Are all options modular? E.g. -a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

@diegofcornejo
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

withfig-bot added a commit that referenced this pull request Nov 2, 2023
@grant0417
Copy link
Member

Hey @diegofcornejo, we change the definition of the script field, can your merge/rebase master and update those fields. You can check the src/docker.ts for reference.

@grant0417
Copy link
Member

Seems like the type check is still failing

@diegofcornejo
Copy link
Contributor Author

Seems like the type check is still failing

Hi @grant0417 , I'm not sure what's wrong because I've checked the code and types in docker.ts. The linter is showing errors. On the other hand, every autocomplete with script (function way) has the same implementation, but in those cases, it seems like the type check doesn't fail."

// podman.ts
script: function (context) {
      if (context[context.length - 1] === "") return undefined;
      const searchTerm = context[context.length - 1];
      return ["podman", "search", searchTerm, "--format", "{{ json . }}"];
    }

script: function (context) {
              let fileFlagIndex, dockerfilePath;
              if (context.includes("-f")) {
                fileFlagIndex = context.indexOf("-f");
                dockerfilePath = context[fileFlagIndex + 1];
              } else if (context.includes("--file")) {
                fileFlagIndex = context.indexOf("--file");
                dockerfilePath = context[fileFlagIndex + 1];
              } else {
                dockerfilePath = "$PWD/Dockerfile";
              }

              return `\\grep -iE 'FROM.*AS' "${dockerfilePath}"`;
            }
// docker.ts
script: function (context) {
      if (context[context.length - 1] === "") return undefined;
      const searchTerm = context[context.length - 1];
      return ["docker", "search", searchTerm, "--format", "{{ json . }}"];
    }

script: function (context) {
              let fileFlagIndex, dockerfilePath;
              if (context.includes("-f")) {
                fileFlagIndex = context.indexOf("-f");
                dockerfilePath = context[fileFlagIndex + 1];
              } else if (context.includes("--file")) {
                fileFlagIndex = context.indexOf("--file");
                dockerfilePath = context[fileFlagIndex + 1];
              } else {
                dockerfilePath = "Dockerfile";
              }

              return ["grep", "-iE", "FROM.*AS", dockerfilePath];
            }

@grant0417
Copy link
Member

If the linter is showing errors for docker you may need to run yarn install again to update your dependencies, the final line of the docker one return ["grep", "-iE", "FROM.*AS", dockerfilePath]; is what it should look like.

@diegofcornejo
Copy link
Contributor Author

If the linter is showing errors for docker you may need to run yarn install again to update your dependencies, the final line of the docker one return ["grep", "-iE", "FROM.*AS", dockerfilePath]; is what it should look like.

I understand now, I fixed the line, everything should be fine!

@grant0417 grant0417 merged commit b3fefec into withfig:master Dec 4, 2023
5 checks passed
@withfig withfig locked and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants