Meta [ Title: "Remote command-line interface for the Meta programming language compiler server" Version: 0.9 Author: "Kaj de Vos" Rights: "Copyright (c) 2021,2022 Kaj de Vos. All rights reserved." License: { BSD-2-Clause https://opensource.org/licenses/BSD-2-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } Purpose: { Compile a Meta program source text on the Meta build server and run it locally. } Notes: { The Meta Project: https://metaproject.frl https://language.metaproject.frl/documentation/ } Example: { Windows: run Unix: (mv run.com run) chmod +x run ./run } Tabs: 4 ] Version= "0.9" Out= ./program.com Metadata= ./metadata.txt Narrow?= all [width= system/console/width width < 80] Either argument= first-of system/program/arguments [ either argument = "about" [ write/line either narrow? [ {Meta remote compiler Compile a Meta program source text via the remote Meta build service and run it locally. Copyright (c) 2021,2022 Kaj de Vos The Meta Project https://metaproject.frl https://language.metaproject.frl/documentation/} ][ {Meta remote compiler Compile a Meta program source text via the remote Meta build service and run it locally. Copyright (c) 2021,2022 Kaj de Vos The Meta Project https://metaproject.frl https://language.metaproject.frl/documentation/} ] ][ either argument = "version" [ write/line version ][ either source: second-of system/program/arguments [ platform= argument ][ source: argument ] ] ] ][ Write/line either narrow? [ {https://language.metaproject.frl/documentation/ Usage: run Show this help text. run run Compile program on the server and run it locally run Specify target platform Syntax: A term to be filled in Commands: about Show program info version Show program version} ][ {Usage: run Show this help text. run run [] Send program text to server to compile, then run it locally. Syntax: A term to be filled in. [] Optional parameter. Commands: about Show program info. version Show program version. Guide: https://language.metaproject.frl/documentation/} ] Status: -1 ; Return warning number for scripts, in case an action was meant ] If source [ Write "Compiling program file " Write/line source Either result= try run join/with join/with join/with join/with join/with join/with join/with join/with join/with "curl -X POST --silent --show-error --data-binary @" source " --dump-header " metadata " https://do.metaproject.frl/compiler/compile/" version "/" any [platform "PC"] " --output " out [ either system/catalog/errors/system/unknown = error: to error! result [ Write/error/line {Error: the "curl" program could not be found.} Write/error/line "Is it installed on your system and accessible?" ][ Write/error "(Networking) error: " Write/error/line error ] ][ Either headers= try open metadata [ Until any [ is-tail headers text?: find/here find/here/tail take/line headers "Content-type: " "text/plain" ] [] Close headers Either text? [ either report= try open out [ Write report Close report ][ ; Save the occurred error from overwriting Error: system/error Write/error "File error: could not access " Write/error out Write/error ": " Write/error/line error ] ][ Unless Windows?= select/case system/environment "=C:" [ ; PowerShell try run join/with "chmod +x " out ] Write "Running file " Write/line out Status: to error! try run either Windows? [ as text! out ][ ; Old ZSh, and sometimes implicit shell invocation, can't do the first run join/with any [ unless try run "which bash" ["bash ./"] unless try run "which sh" ["sh ./"] ; Hope this shell can do the first run "./" ] out ] ] ][ Error: system/error Write/error "File error: could not access " Write/error metadata Write/error ": " Write/error/line error ] ] ] Status