@@ -1014,70 +1014,6 @@ If CONTEXT is not provided, use the current context."
10141014 (items (append (alist-get 'items resource-list) '())))
10151015 (-map (lambda (item ) (let-alist item .metadata.name)) items)))
10161016
1017- (cl-defun kele-get (kind name &key group version context namespace )
1018- " Get resource KIND by NAME and display it in a buffer.
1019-
1020- KIND should be the plural form of the kind's name, e.g. \" pods\"
1021- instead of \" pod.\"
1022-
1023- If GROUP and VERSION are nil, the function will look up the
1024- possible group-versions for the resource KIND. If there is more
1025- than one group-version associated with the resource KIND, the
1026- function will signal an error.
1027-
1028- If GROUP is nil, look up KIND in the core API group.
1029-
1030- If CONTEXT is nil, use the current context.
1031-
1032- If NAMESPACE is nil and the resource KIND is namespaced, use the
1033- default namespace of the given CONTEXT.
1034-
1035- If NAMESPACE is provided for a non-namespaced resource KIND,
1036- throws an error."
1037- ; ; TODO (#72): Start proxy server asynchronously here; await on it right when it's
1038- ; ; needed
1039- (interactive (let* ((ctx (kele-current-context-name))
1040- (kind (completing-read
1041- " Kind: "
1042- (kele--get-resource-types-for-context ctx :verb 'get )))
1043- (gvs (kele--get-groupversions-for-type
1044- kele--global-discovery-cache
1045- kind
1046- :context ctx))
1047- (gv (if (= (length gvs) 1 )
1048- (car gvs)
1049- (completing-read (format " Desired group-version of `%s' : "
1050- kind)
1051- gvs)))
1052- (group (when (s-contains-p " /" gv) (car (s-split " /"
1053- gv))))
1054- (version (if (s-contains-p " /" gv) (cadr (s-split " /" gv))
1055- gv))
1056- (ns (if (not (kele--resource-namespaced-p
1057- kele--global-discovery-cache
1058- gv
1059- kind
1060- :context ctx))
1061- nil
1062- (completing-read (format " Namespace to get `%s/%s' from: "
1063- gv
1064- kind)
1065- (kele--get-namespaces ctx)))))
1066- (list kind
1067- (completing-read
1068- " Name: "
1069- (-cut kele--resources-complete <> <> <>
1070- :cands (kele--fetch-resource-names group version kind :namespace ns :context ctx)))
1071- :group group
1072- :version version
1073- :context ctx
1074- :namespace ns)))
1075- (kele--render-object (kele--get-resource kind name
1076- :group group
1077- :version version
1078- :namespace namespace
1079- :context context)))
1080-
10811017(cl-defun kele--render-object (object &optional buffer )
10821018 " Render OBJECT in a buffer as YAML.
10831019
@@ -1437,7 +1373,7 @@ Otherwise, returns the current context name from kubeconfig."
14371373 value
14381374 (kele-current-context-name)))
14391375
1440- (cl-defun kele--get-namespace-arg (&key use-default group-version kind )
1376+ (cl-defun kele--get-namespace-arg (&key use-default group-version kind (prompt " Namespace: " ) )
14411377 " Get the value to use for Kubernetes namespace.
14421378
14431379In order of priority, this function attempts the following:
@@ -1451,7 +1387,7 @@ In order of priority, this function attempts the following:
14511387- If the resource type specified by GROUP-VERSION and KIND is not
14521388 namespaced, return nil;
14531389
1454- - Otherwise, ask the user to select a namespace."
1390+ - Otherwise, ask the user to select a namespace using PROMPT ."
14551391 (let ((transient-arg-maybe (->> transient-current-command
14561392 (transient-args)
14571393 (transient-arg-value " --namespace=" ))))
@@ -1464,7 +1400,7 @@ In order of priority, this function attempts the following:
14641400 group-version
14651401 kind))
14661402 nil )
1467- (t (completing-read " Namespace: "
1403+ (t (completing-read prompt
14681404 (kele--get-namespaces (kele--get-context-arg)))))))
14691405
14701406(cl-defun kele--get-groupversion-arg (&optional kind )
@@ -1561,15 +1497,12 @@ is not namespaced, returns an error."
15611497If BUTTON is provided, pull the resource information from the
15621498 button properties. Otherwise, get it from the list entry."
15631499 (interactive nil kele-list-mode)
1564- (-let* ((id (if button (button-get button 'kele-resource-id ) (tabulated-list-get-id )))
1565- ((group version) (kele--groupversion-split
1566- (kele--list-entry-id-group-version id))))
1567- (kele-get (kele--list-entry-id-kind id)
1568- (kele--list-entry-id-name id)
1569- :group group
1570- :version version
1571- :context (kele--list-entry-id-context id)
1572- :namespace (kele--list-entry-id-namespace id))))
1500+ (-let* ((id (if button (button-get button 'kele-resource-id ) (tabulated-list-get-id ))))
1501+ (kele-get (kele--list-entry-id-context id)
1502+ (kele--list-entry-id-namespace id)
1503+ (kele--list-entry-id-group-version id)
1504+ (kele--list-entry-id-kind id)
1505+ (kele--list-entry-id-name id))))
15731506
15741507(cl-defun kele--get-kind-arg ()
15751508 " Get the kind to work with.
@@ -1582,39 +1515,51 @@ if it's set. Otherwise, prompts user for input."
15821515 (kele--get-resource-types-for-context
15831516 (kele--get-context-arg)))))
15841517
1585- (transient-define-suffix kele--get ()
1518+ (transient-define-suffix kele-get (context namespace group-version kind name)
1519+ " Get resource KIND by NAME and display it in a buffer.
1520+
1521+ GROUP-VERSION, NAMESPACE, KIND, and CONTEXT are all used to identify the
1522+ resource type to query for.
1523+
1524+ KIND should be the plural form of the kind's name, e.g. \" pods\"
1525+ instead of \" pod.\" "
15861526 :key " g"
15871527 :description
15881528 (lambda ()
15891529 (--> (oref transient--prefix scope)
15901530 (alist-get 'kind it)
15911531 (propertize it 'face 'warning )
15921532 (format " Get a single %s " it)))
1593- (interactive )
1594- (-let* ((kind (kele--get-kind-arg))
1595- ((group version) (kele--groupversion-split (kele--get-groupversion-arg)))
1596- (ns (kele--get-namespace-arg
1597- :group-version (kele--get-groupversion-arg)
1598- :kind kind
1599- :use-default nil ))
1600- (cands (kele--fetch-resource-names group version kind
1601- :namespace ns
1602- :context (kele--get-context-arg)))
1603- (name (completing-read " Name: " (-cut kele--resources-complete <> <> <> :cands cands))))
1604- (kele-get kind name
1605- :group group
1606- :version version
1607- :namespace ns
1608- :context (kele--get-context-arg))))
1533+ (interactive
1534+ (-let* ((kind (kele--get-kind-arg))
1535+ (gv (kele--get-groupversion-arg kind))
1536+ ((group version) (kele--groupversion-split gv))
1537+ (ns (kele--get-namespace-arg
1538+ :group-version gv
1539+ :kind kind
1540+ :use-default nil ))
1541+ (cands (kele--fetch-resource-names group version kind
1542+ :namespace ns
1543+ :context (kele--get-context-arg)))
1544+ (name (completing-read " Name: " (-cut kele--resources-complete <> <>
1545+ <> :cands cands))))
1546+ (list (kele--get-context-arg) ns gv kind name)))
1547+ (-let (((group version) (kele--groupversion-split group-version)))
1548+ (kele--render-object (kele--get-resource kind name
1549+ :group group
1550+ :version version
1551+ :namespace namespace
1552+ :context context))))
16091553
16101554(transient-define-prefix kele-resource (group-versions kind)
1555+ " Work with Kubernetes resources."
16111556 [" Arguments"
16121557 (kele--context-infix)
16131558 (kele--groupversions-infix)
16141559 (kele--namespace-infix)]
16151560
16161561 [" Actions"
1617- (kele-- get)
1562+ (kele-get)
16181563 (kele-list)]
16191564
16201565 (interactive (let* ((context (kele-current-context-name))
0 commit comments