commit
98806725a3
@ -0,0 +1,22 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2024 William Perron
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
@ -0,0 +1,17 @@
|
|||||||
|
# Global Increment
|
||||||
|
|
||||||
|
This program creates a persisted sequence that increments every time it is
|
||||||
|
called, useful when you need to call the same command over and over and need to
|
||||||
|
pass an ever-increasing number to it. Takes an optional positional argument that
|
||||||
|
acts as a key, allowing multiple sequences to be used.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
incr [KEY]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Copy the `incr` file somewhere in your `PATH`. Needs [Deno][https://deno.com]
|
||||||
|
installed.
|
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env deno run --unstable-kv --allow-read --allow-write
|
||||||
|
// deno-lint-ignore-file prefer-const
|
||||||
|
import { parseArgs } from "jsr:@std/cli";
|
||||||
|
|
||||||
|
let db = await Deno.openKv("incrementer");
|
||||||
|
|
||||||
|
if (import.meta.main) {
|
||||||
|
let args = parseArgs(Deno.args);
|
||||||
|
let ns = args["_"][0] ?? "_global";
|
||||||
|
|
||||||
|
let old = await db.get([ns]);
|
||||||
|
|
||||||
|
let nextVal = old.value + 1;
|
||||||
|
let n = await db.atomic()
|
||||||
|
.check(old)
|
||||||
|
.set([ns], nextVal)
|
||||||
|
.commit();
|
||||||
|
|
||||||
|
if (n.ok === false) {
|
||||||
|
console.error("failed to commit result to Deno KV");
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(nextVal);
|
||||||
|
}
|
Loading…
Reference in new issue