kubectl [options] VERB ...: the verb and its -f / -k / -R. */
| 1501 | |
| 1502 | /* kubectl [options] VERB ...: the verb and its -f / -k / -R. */ |
| 1503 | static void sh_kubectl_parse(const sh_argv_t *a, int from, sh_kubectl_t *k) { |
| 1504 | k->verb = -1; |
| 1505 | int i = from; |
| 1506 | while (i < a->n && k->verb < 0) { |
| 1507 | const char *w = a->v[i]; |
| 1508 | if (!w) { |
| 1509 | return; |
| 1510 | } |
| 1511 | if (w[0] != '-') { |
| 1512 | k->verb = i++; |
| 1513 | break; |
| 1514 | } |
| 1515 | i += (sh_in(w, SH_KUBECTL_VALUED) && !strchr(w, '=')) ? PAIR_LEN : SKIP_ONE; |
| 1516 | } |
| 1517 | for (; i < a->n; i++) { |
| 1518 | const char *w = a->v[i]; |
| 1519 | if (!w || w[0] != '-') { |
| 1520 | continue; |
| 1521 | } |
| 1522 | const char *next = i + SKIP_ONE < a->n ? a->v[i + SKIP_ONE] : NULL; |
| 1523 | if (strcmp(w, "--recursive") == 0) { |
| 1524 | k->recursive = true; |
| 1525 | } else if (strcmp(w, "--filename") == 0 || strcmp(w, "--kustomize") == 0) { |
| 1526 | bool fl = w[PAIR_LEN] == 'f'; |
| 1527 | sh_kubectl_add(fl ? &k->files : &k->kusts, fl ? &k->nfiles : &k->nkusts, |
| 1528 | fl ? &k->cap_files : &k->cap_kusts, next); |
| 1529 | i++; |
| 1530 | } else if (sh_starts(w, "--filename=")) { |
| 1531 | sh_kubectl_add(&k->files, &k->nfiles, &k->cap_files, strchr(w, '=') + SKIP_ONE); |
| 1532 | } else if (sh_starts(w, "--kustomize=")) { |
| 1533 | sh_kubectl_add(&k->kusts, &k->nkusts, &k->cap_kusts, strchr(w, '=') + SKIP_ONE); |
| 1534 | } else if (w[SKIP_ONE] != '-') { |
| 1535 | /* a cluster of short options: -f, -k, -R, -Rf */ |
| 1536 | size_t len = strlen(w); |
| 1537 | bool ok = len > SKIP_ONE; |
| 1538 | for (size_t c = SKIP_ONE; c < len; c++) { |
| 1539 | ok = ok && ((w[c] >= 'a' && w[c] <= 'z') || (w[c] >= 'A' && w[c] <= 'Z')); |
| 1540 | } |
| 1541 | if (!ok) { |
| 1542 | continue; |
| 1543 | } |
| 1544 | if (strchr(w, 'R')) { |
| 1545 | k->recursive = true; |
| 1546 | } |
| 1547 | char last = w[len - SKIP_ONE]; |
| 1548 | if (last == 'f' || last == 'k') { |
| 1549 | sh_kubectl_add(last == 'f' ? &k->files : &k->kusts, |
| 1550 | last == 'f' ? &k->nfiles : &k->nkusts, |
| 1551 | last == 'f' ? &k->cap_files : &k->cap_kusts, next); |
| 1552 | i++; |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | static void sh_deploy_src(sh_t *s, TSNode cmd, const sh_src_t *src); |
| 1559 |
no test coverage detected