diff --git a/README.md b/README.md index 2b653b3..461578a 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,32 @@ like `10s`, `5m`, or `1h` to indicate how many seconds, minutes, or hours the ap jag run -D jag.timeout=10s service.toit ``` +## Defines +Jaguar supports defining values that can be used in your Toit code. This is done through +the `-D` option. Its primary use is to configure Jaguar (see below for temporarily disabling +Jaguar), but it can also be used to pass values to your Toit code. + +All defined values that are available in the `jag.defines` assets, where they are stored as +Tison. The `encoding.tison` library has functions to extract these values from the assets. + +``` sh +jag run -D my-define=499 defines.toit +``` + +``` toit +// defines.toit +import encoding.tison +import system.assets + +main: + defines := assets.decode.get "jag.defines" + --if-present=: tison.decode it + --if-absent=: {:} + if defines is not Map: + throw "defines are malformed" + print defines["my-define"] +``` + ## Temporarily disabling Jaguar You can disable Jaguar while your application runs using the `-D jag.disabled`. This is useful if Jaguar otherwise interferes with your application. As an example, consider an application that uses the WiFi to setup a diff --git a/cmd/jag/commands/device_network.go b/cmd/jag/commands/device_network.go index 1ce1f8c..094e7f9 100644 --- a/cmd/jag/commands/device_network.go +++ b/cmd/jag/commands/device_network.go @@ -1,4 +1,4 @@ -// Copyright (C) 2021 Toitware ApS. All rights reserved. +// Copyright (C) 2024 Toitware ApS. All rights reserved. // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. diff --git a/cmd/jag/commands/run.go b/cmd/jag/commands/run.go index 5dd4c90..2a197e6 100644 --- a/cmd/jag/commands/run.go +++ b/cmd/jag/commands/run.go @@ -280,6 +280,7 @@ func sendCodeFromFile( // We assume the error has been printed. // Mark the command as silent to avoid printing the error twice. cmd.SilenceErrors = true + cmd.SilenceUsage = true return err } } @@ -381,6 +382,7 @@ func sendCodeFromFile( // We assume the error has been printed. // Mark the command as silent to avoid printing the error twice. cmd.SilenceErrors = true + cmd.SilenceUsage = true return err } @@ -389,6 +391,7 @@ func sendCodeFromFile( // We just printed the error. // Mark the command as silent to avoid printing the error twice. cmd.SilenceErrors = true + cmd.SilenceUsage = true return err } fmt.Printf("Success: Sent %dKB code to '%s'\n", len(b)/1024, device.Name()) diff --git a/go.mod b/go.mod index 1e20e73..0915bf4 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/skeema/knownhosts v1.2.1 // indirect github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.17.0 - github.com/toitlang/tpkg v0.0.0-20230928125532-1be02ac647ae + github.com/toitlang/tpkg v0.0.0-20240919112017-273e738f33d0 github.com/toitware/ubjson v0.0.0-20231002110407-71c8fab5e607 github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c go.bug.st/serial v1.6.1 diff --git a/go.sum b/go.sum index 17c20f5..2d06c47 100644 --- a/go.sum +++ b/go.sum @@ -1035,6 +1035,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -1418,7 +1420,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= @@ -1716,8 +1717,8 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/toitlang/tpkg v0.0.0-20230928125532-1be02ac647ae h1:vmp2+atDvyFKE6TOSepzmrtNuSy8bXW5WagF3ZuJfq0= -github.com/toitlang/tpkg v0.0.0-20230928125532-1be02ac647ae/go.mod h1:L57D7q11LI+dCu8icjX3Lh2qRidFP5FrbFGdE7c1Bpw= +github.com/toitlang/tpkg v0.0.0-20240919112017-273e738f33d0 h1:XkdGj+nHUvEZYPTe8T5JGDeKEchf8tjcyKPaj/6kIG4= +github.com/toitlang/tpkg v0.0.0-20240919112017-273e738f33d0/go.mod h1:Hjfmv2z6MRbjgaGHVdRizYOHJhxQkQZesO3qx75Qk4w= github.com/toitware/ubjson v0.0.0-20231002110407-71c8fab5e607 h1:0dQXytY4gpPS0LaCFF4FglOhc53jnpFq4RnuEJupJrw= github.com/toitware/ubjson v0.0.0-20231002110407-71c8fab5e607/go.mod h1:LodXJFCaPxCR6kxbtjumQpO85yzrRkFpseNkbd5nXjU= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=