From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: How can i make executable guile file to process command line arguments? Date: Thu, 18 Aug 2022 17:58:39 +0000 Message-ID: <8be2854b-b8f4-b016-b820-e937c8f17c4f@posteo.de> References: <6e5568cb-2924-010b-84b3-1fbf3482300b@rixotstudio.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8657"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Jacob Hrbek Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Aug 18 19:59:01 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oOjnI-000235-JQ for guile-user@m.gmane-mx.org; Thu, 18 Aug 2022 19:59:00 +0200 Original-Received: from localhost ([::1]:36880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOjnH-0004Sn-Hh for guile-user@m.gmane-mx.org; Thu, 18 Aug 2022 13:58:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOjn4-0004RI-TS for guile-user@gnu.org; Thu, 18 Aug 2022 13:58:47 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:55951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOjn1-00045R-VR for guile-user@gnu.org; Thu, 18 Aug 2022 13:58:46 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id D3566240029 for ; Thu, 18 Aug 2022 19:58:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1660845520; bh=XiuFEaRx3y4D/gzBmE2EBc974bcv99jmVk4jR8I+KVY=; h=Date:Subject:To:Cc:From:From; b=ab37VqTO/2VuPjVtwnHP+cutumZ17FHDSOk3lDo2ScRHkcOgBvlRDnoD8sj7uxDBC SyetdbqeOq2yT24IRxqV+WqXcQOzqF6VRlPhztf1wiPrAR7dZjcSuf25uxBcuLw8jj bgw2FzXZXc9iWluExjkHeXqroZ7jYKo47bBV+cNyda+AJ6eTXHc9kL3tTtKfT7lwUp VN0ABQn+iyoTUcAgRtWpOXwJayrVufLpyqb9/GbMziBlin7Nkv7ZfkkL0i+L0GpSde SDlwVY4Yzcfk9a1pD4EyuHTy27Eqfq4Cb13/uBkBn9h7Q8pq1Q7XtbgAv7EVzWQ4r5 Rd6TjY5qLHUWQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4M7t0w0P2Fz9rxP; Thu, 18 Aug 2022 19:58:39 +0200 (CEST) Content-Language: en-US In-Reply-To: <6e5568cb-2924-010b-84b3-1fbf3482300b@rixotstudio.cz> Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18526 Archived-At: Hello Jacob, On 8/18/22 16:01, Jacob Hrbek wrote: > I have this file which i use to interact with a version controlled repository > similar to a Makefile. > > How can i make it work with e.g. `./file.scm echo wheee` -> Will execute the > `(define (echo msg) ...)` and output `wheee` in the terminal? > > FWIW preferably i want it to work like `./file.scm echo whee build` so that it > would output `wheee` and then ran the `(define (build) ...)` task too.. > > #!/usr/bin/env sh > exec guile -s "$0" "$@" > !# > ;;; This file is used to interact with the project > > ;;; ==== [START] TO BE INCLUDED IN A LIBRARY [START] ==== ;;; > > ;; Get path to the current filename > (define-public %repo-root (dirname (current-filename))) > > ;;; ==== [STOP] TO BE INCLUDED IN A LIBRARY [STOP] ==== ;;; > > ;; FIXME-QA(Krey): We need to define an alternative to `(define (task)...)` to > be more workable and faster to write > > ;;; Tasks > ;; DESIGN(Krey): Build the system configuration > (define (build) >   (system* "guix" >        "system" >        "build" >        (string-append %repo-root "/config.scm"))) > > ;; DESIGN(Krey): Deploy the system configuration on the current system > (define (deploy) >   (system* "guix" >        "system" >        "reconfigure" >        (string-append %repo-root "/config.scm"))) > > ;; DESIGN(Krey): Build the bare minimal image for rockpro64 > (define (tools-minimal-rockpro64) >   (system* "guix" >        "system" >        "--system=aarch64-linux" >        "image" >        (string-append %file-root "/config.scm"))) > > ;; Processing of cli arguments > (define (echo msg) (system* "echo" msg)) > > ;; DESIGN(Krey): Expecting to process the command-line args here > ;; HOTFIX(Krey): Didn't figure out how to do it yet, so currently hard-coding > ; deploy > > ;(quote (cdr (command-line))) > ;;(match (command-line) ((_ "build") (build))) If you are looking for having command line arguments like --some-flag, --my-val=123 and so on, you might want to take a look at the examples in my repo: https://notabug.org/ZelphirKaltstahl/guile-examples/src/master/command-line-arguments. Maybe your use-case can be implemented using such command line arguments, instead of having "raw arguments". Regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl