Subject: [PATCH v2] gnu: Add linode-cli.

From: raingloom <[email-masked]>
Date: Mon, 15 Aug 2022 13:42:28 +0200

From: Csepp <[email-masked]>

* gnu/packages/python-xyz.scm (linode-cli) (linode-openapi-spec): New variables.
---
 gnu/packages/python-xyz.scm | 67 +++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index e5326274c0..f299476f47 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -30353,3 +30353,70 @@ (define-public i3-autotiling
      "Script for Sway and i3 to automatically switch the horizontal/vertical
  window split orientation.")
     (license license:gpl3)))
+
+;; linode-cli would normally fetch this at build time
+;; TODO: is there a way to refer to previous versions? is there even a point
+;; in trying to?
+(define linode-openapi-spec
+  (origin
+    (method url-fetch)
+    (uri "https://www.linode.com/docs/api/openapi.yaml")
+    (sha256
+     (base32
+      "1jcjfnagjihcy03fcmn5sghdf7a80798xjgj1x7z3ncqwd5aggwg"))))
+
+(define-public linode-cli
+  (package
+    (name "linode-cli")
+    (version "5.22.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/linode/linode-cli")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32
+         "1fv53wikx745kci86xrsq9kfsgv0a65srhywdw32cab1wywwpn2z"))))
+    (build-system python-build-system)
+    (arguments (list
+                #:tests? #f ;; requires personal access token
+                #:phases
+                #~(modify-phases %standard-phases
+                    (add-after 'build 'bake-api
+                      (lambda _
+                        ;; The "build" make target tries to do some Python 2
+                        ;; stuff, so instead we just take the two lines we care
+                        ;; about:
+                        (invoke "python3" "-m" "linodecli" "bake"
+                                #+linode-openapi-spec
+                                "--skip-config")
+                        (copy-file "data-3" "linodecli/data-3")))
+                    (add-before 'install 'fix-bash-completions-path
+                      (lambda _
+                        ;; rename it so setup.py thinks it's missing and
+                        ;; doesn't try to install it to /etc
+                        (rename-file "linode-cli.sh" "completions")
+                        ;; TODO for some reason these don't work?
+                        ;; I don't use bash, so I leave it for someone else to
+                        ;; figure out.
+                        (install-file
+                         "completions"
+                         (string-append #$output "/share/bash-completion/"))))
+                    (replace 'sanity-check
+                      (lambda _
+                        ;; this way it doesn't ask for an access token
+                        (invoke "linode-cli" "--version" "--skip-config"))))))
+    (inputs
+     (list
+      python-terminaltables
+      python-requests
+      python-pyyaml))
+    (synopsis "Tool for managing Linode resources")
+    (home-page "https://www.linode.com/docs/products/tools/cli/")
+    (description
+     "A wrapper around the Linode API, which gives you the ability to manage
+your Linode account from the command line.  Almost any task that can be done
+through the Cloud Manager can also be performed through the CLI.")
+    (license license:bsd-3)))
-- 
2.37.1