~skin/ip-finder

cd1ac06645a1b70a5949b3e3f7b9162f1fe8b6f8 — Skin 1 year, 4 months ago
Got the tests to pass
10 files changed, 163 insertions(+), 0 deletions(-)

A .gitattributes
A .gitignore
A LICENSE
A README.md
A ip-finder.asd
A ip-finder.ros
A qlfile
A qlfile.lock
A src/main.lisp
A tests/main.lisp
A  => .gitattributes +18 -0
@@ 1,18 @@
# Linux
*.sh text eol=lf

# Windows
*.ps1 text eol=crlf
*.bat text eol=crlf

# Both OS's
*.lisp text
*.asd text
*.md text
*.lock text
qlfile text
.gitignore text

# Images
*.png binary
*.jpg binary
\ No newline at end of file

A  => .gitignore +19 -0
@@ 1,19 @@
# Lisp build files

*.abcl
*.fasl
*.dx32fsl
*.dx64fsl
*.lx32fsl
*.lx64fsl
*.x86f

# Editor save filees

*~
.#*
.*.sw[a-z]

# Qlot files
/.qlot/
/.bundle-libs/
\ No newline at end of file

A  => LICENSE +20 -0
@@ 1,20 @@
Copyright 2023 Daniel Jay Haskin

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file

A  => README.md +6 -0
@@ 1,6 @@
# IP Finder
This project is written in Common Lisp. It is exists primarily as a
demonstration for how to set up Common Lisp Projects.

# How To Build From Source
Run `ros build ip-finder.ros`. This command will create a thing.
\ No newline at end of file

A  => ip-finder.asd +27 -0
@@ 1,27 @@
(defsystem "ip-finder"
           :version "0.1.0"
           :author "Daniel Jay Haskin"
           :license "MIT"
           :depends-on (
                        "dexador"
                        "cl-yaml"
                        )
           :components ((:module "src"
                                 :components
                                 ((:file "main"))))
           :description "IP address finder."
           :in-order-to ((test-op (test-op "ip-finder/tests"))))

(defsystem "ip-finder/tests"
           :version "0.1.0"
           :author "Daniel Jay Haskin"
           :license "MIT"
           :depends-on (
                        "ip-finder"
                        "rove"
                        )
           :components ((:module "tests"
                                 :components
                                 ((:file "main"))))
           :description "Test system for ip-finder"
           :perform (test-op (op c) (symbol-call :rove :run c)))
\ No newline at end of file

A  => ip-finder.ros +19 -0
@@ 1,19 @@
#!/bin/sh
#|-*- mode:lisp -*-|#
#|
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
  (ros:ensure-asdf)
  #+quicklisp(ql:quickload '() :silent t)
  (asdf:load-system "ip-finder")
  )

(defpackage :ros.script.ip-finder.3892512754
  (:use :cl))
(in-package :ros.script.ip-finder.3892512754)

(defun main (&rest argv)
  (declare (ignorable argv))
  (ip-finder:main))
;;; vim: set ft=lisp lisp:

A  => qlfile +2 -0
@@ 1,2 @@
ql dexador
git cl-yaml https://github.com/eudoxia0/cl-yaml.git :branch master
\ No newline at end of file

A  => qlfile.lock +12 -0
@@ 1,12 @@
("quicklisp" .
 (:class qlot/source/dist:source-dist
  :initargs (:distribution "http://beta.quicklisp.org/dist/quicklisp.txt" :%version :latest)
  :version "2023-02-15"))
("dexador" .
 (:class qlot/source/ql:source-ql
  :initargs (:%version :latest)
  :version "ql-2023-02-15"))
("cl-yaml" .
 (:class qlot/source/git:source-git
  :initargs (:remote-url "https://github.com/eudoxia0/cl-yaml.git" :branch "master")
  :version "git-12c84d43b3f57f332774c780a2e4a20eee7f47de"))

A  => src/main.lisp +24 -0
@@ 1,24 @@
(in-package #:cl-user)
(defpackage
  #:ip-finder
  (:use #:cl)
  (:documentation
    "
    The ip-finder command gets the public IP address from the caller as
    observed by `icanhazip.com`.
    "
    )
    (:import-from #:dexador)
    (:import-from #:cl-yaml)
    (:export
      main))
(in-package #:ip-finder)

(defun main (&key
              ;; Dependency Injection for tests
              (out-stream t)
              (http-get #'dexador:get)
              (url "https://icanhazip.com"))
    "Get my IP address."
    (let ((ip (string-trim "\n\t " (funcall http-get url))))
      (format out-stream "ip: ~A" (cl-yaml:emit-to-string ip))))
\ No newline at end of file

A  => tests/main.lisp +16 -0
@@ 1,16 @@
(in-package #:cl-user)
(defpackage #:ip-finder/tests
  (:use #:cl
        #:rove)
  (:import-from
    #:ip-finder))

(in-package :ip-finder/tests)

(deftest
  main
  (testing "main"
    (ok (equal (ip-finder:main :out-stream nil :http-get (lambda (addr)
                                    (declare (ignore addr))
                                    "  127.0.0.1\n\n\t "))
              "ip: \"127.0.0.1\""))))