This commit is contained in:
2024-12-25 12:37:24 +01:00
parent f38f2f4b16
commit 4848703a8b
3 changed files with 70 additions and 1 deletions

View File

@@ -64,6 +64,7 @@ command_exists() {
export DIR_BASE="$HOME"
export DIR_BUILD="/tmp"
export DIR_CODE="$DIR_BASE/code"
export DIR_CODE_V="$DIR_BASE/_code"
function sshknownkeysadd {
mkdir -p ~/.ssh
@@ -292,7 +293,8 @@ if [ "$RESET" = true ] || ! command_exists v; then
# Only clone and install if directory doesn't exist
if [ ! -d ~/code/v ]; then
echo "Installing V..."
cd ~/code
mkdir -p ~/_code
cd ~/_code
git clone --depth=1 https://github.com/vlang/v
cd v
make

56
lib/osal/done.v Normal file
View File

@@ -0,0 +1,56 @@
module osal
import freeflowuniverse.crystallib.core.base
import freeflowuniverse.crystallib.data.dbfs
import freeflowuniverse.crystallib.ui.console
fn donedb() !&dbfs.DB {
mut context := base.context()!
mut collection := context.dbcollection()!
mut db := collection.db_get_create(name: 'todo', withkeys: true)!
return &db
}
pub fn done_set(key string, val string) ! {
mut db := donedb()!
db.set(key: key, value: val)!
}
pub fn done_get(key string) ?string {
mut db := donedb() or { panic(err) }
return db.get(key: key) or { return none }
}
pub fn done_delete(key string) ! {
mut db := donedb()!
db.delete(key: key)!
}
pub fn done_get_str(key string) string {
val := done_get(key) or { panic(err) }
return val
}
pub fn done_get_int(key string) int {
val := done_get(key) or { panic(err) }
return val.int()
}
pub fn done_exists(key string) bool {
mut db := donedb() or { panic(err) }
return db.exists(key: key) or { false }
}
pub fn done_print() ! {
mut db := donedb()!
mut output := 'DONE:\n'
for key in db.keys('')! {
output += '\t${key} = ${done_get_str(key)}\n'
}
console.print_debug('${output}')
}
pub fn done_reset() ! {
mut db := donedb()!
db.destroy()!
}

11
lib/osal/done_test.v Normal file
View File

@@ -0,0 +1,11 @@
module osal
fn test_done_set() ! {
done_set('mykey', 'myvalue')!
assert done_exists('mykey')
assert done_get('mykey')! == 'myvalue'
assert done_get_str('mykey') == 'myvalue'
assert done_get_int('mykey') == 0
done_print()!
done_reset()!
}