MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_find

Function sh_find

src/pipeline/pass_shell.c:1688–1734  ·  view source on GitHub ↗

find DIR [-type f] [-name G] [-maxdepth N] -exec kubectl apply -f {} \; */

Source from the content-addressed store, hash-verified

1686
1687/* find DIR [-type f] [-name G] [-maxdepth N] -exec kubectl apply -f {} \; */
1688static void sh_find(sh_t *s, TSNode cmd, const sh_argv_t *a, int prog) {
1689 int i = prog + SKIP_ONE;
1690 if (i >= a->n || !a->v[i] || a->v[i][0] == '-') {
1691 return;
1692 }
1693 const char *root = a->v[i++];
1694 sh_find_t f = {false, NULL, SH_NO_DEPTH};
1695 while (i < a->n) {
1696 const char *w = a->v[i];
1697 const char *next = i + SKIP_ONE < a->n ? a->v[i + SKIP_ONE] : NULL;
1698 if (!w) {
1699 return;
1700 }
1701 if (strcmp(w, "-exec") == 0) {
1702 break;
1703 }
1704 if (strcmp(w, "-name") == 0 && next) {
1705 f.name = next;
1706 } else if (strcmp(w, "-maxdepth") == 0 && next && sh_numberish(next)) {
1707 f.maxdepth = (int)strtol(next, NULL, SH_DEC);
1708 } else if (!(strcmp(w, "-type") == 0 && sh_eq(next, "f"))) {
1709 return;
1710 }
1711 i += PAIR_LEN; /* each test takes one value */
1712 }
1713 /* -exec PROGRAM ... {} ; */
1714 sh_argv_t e = {0};
1715 for (i++; i < a->n && !sh_eq(a->v[i], ";") && !sh_eq(a->v[i], "+"); i++) {
1716 sh_argv_push(&e, a->v[i], a->split[i], a->span[PAIR_LEN * i],
1717 a->span[PAIR_LEN * i + SKIP_ONE]);
1718 }
1719 int p = sh_program(s, &e);
1720 if (p >= 0 && e.v[p] && strcmp(sh_basename(e.v[p]), "kubectl") == 0) {
1721 sh_kubectl_t k = {0};
1722 sh_kubectl_parse(&e, p + SKIP_ONE, &k);
1723 const char *verb = k.verb >= 0 ? e.v[k.verb] : NULL;
1724 if ((sh_eq(verb, "apply") || sh_eq(verb, "create") || sh_eq(verb, "replace")) &&
1725 k.nfiles == SKIP_ONE && k.nkusts == 0 && sh_eq(k.files[0], "{}")) {
1726 sh_targets_t ts = {0};
1727 sh_targets_of(s, root, sh_t_found, &f, &ts);
1728 sh_hit_all(s, cmd, "kubectl", &ts, false);
1729 cbm_free(CBM_MEM_CLASS_OTHER, ts.items);
1730 }
1731 sh_kubectl_free(&k);
1732 }
1733 sh_argv_free(&e);
1734}
1735
1736/* One command of a pipeline (or a lone one): its deploys; *out: what it
1737 * writes to the pipe, when that is a kustomize build or a helm template. */

Callers 1

sh_deploy_commandFunction · 0.85

Calls 11

sh_numberishFunction · 0.85
sh_eqFunction · 0.85
sh_argv_pushFunction · 0.85
sh_programFunction · 0.85
sh_basenameFunction · 0.85
sh_kubectl_parseFunction · 0.85
sh_targets_ofFunction · 0.85
sh_hit_allFunction · 0.85
cbm_freeFunction · 0.85
sh_kubectl_freeFunction · 0.85
sh_argv_freeFunction · 0.85

Tested by

no test coverage detected