From 570d29c368abdc9ef9952bd7cce38809be9c9c91 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 6 Mar 2024 00:10:59 +0000 Subject: [PATCH] pass command line params to run instead of reffing global --- pkgs/ifwait/ifwait.fnl | 11 ++++++----- pkgs/ifwait/test-ifwait.fnl | 8 ++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkgs/ifwait/ifwait.fnl b/pkgs/ifwait/ifwait.fnl index 70194eb..64d3825 100644 --- a/pkgs/ifwait/ifwait.fnl +++ b/pkgs/ifwait/ifwait.fnl @@ -32,18 +32,19 @@ {})] (. got params.expecting))) -(fn run [event-fn] +(fn run [args event-fn] (let [parameters - (assert (parse-args arg) - (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))] + (assert (parse-args args) + (.. "Usage: ifwait [-v] ifname [present|up|running]"))] (when parameters.verbose - (print (.. (. arg 0) ": waiting for " + (print (.. "ifwait: waiting for " parameters.link " to be " parameters.expecting))) (each [e (event-fn) &until (run-event parameters e)] true))) -(when (not (= (. arg 0) "test")) (run #(nl.events {:link true}))) +(when (not (= (. arg 0) "test")) + (run arg #(nl.events {:link true}))) { : run } diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 67b8ac5..3c8bdd7 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -11,15 +11,11 @@ (icollect [_ ast parse] ast))) - -(set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test"))) - +(set _G.arg (doto [] (tset 0 "test"))) (local ifwait (require :ifwait)) - - (let [gen (event-generator (file-events "events-fixture"))] - (ifwait.run #gen) + (ifwait.run ["-v" "dummy0" "up"] #gen) (match (pcall gen) (true _) true (false msg) (error "didn't detect dummy0 up event")))