Compare commits

...

9 Commits

Author SHA1 Message Date
ge
a35f385574 remove Makefile 2025-05-29 23:59:12 +03:00
ge
21faadcfc7 makefile: fix 2025-04-22 20:03:50 +03:00
ge
d744ebf9f2 cmd: rename dataunit to datasize 2025-04-22 19:58:46 +03:00
ge
13897bf625 ci: add tests CI 2025-04-22 19:56:58 +03:00
ge
13767d8c0c all: stop using src/ dir 2025-04-22 19:51:49 +03:00
ge
72bef1ea47 doc: add .vdocignore
Some checks failed
CI / build (push) Has been cancelled
CI / deploy (push) Has been cancelled
2025-03-29 20:45:24 +03:00
e89bf7dbc1 ci: Add docs website
Some checks failed
CI / build (push) Has been cancelled
CI / deploy (push) Has been cancelled
2025-03-29 20:41:58 +03:00
ge
53a0d77ecb bump version 2025-01-13 20:55:02 +03:00
ge
f4fe18ed49 fix example 2025-01-13 20:54:32 +03:00
8 changed files with 78 additions and 32 deletions

48
.github/workflows/docs.yaml vendored Normal file
View File

@ -0,0 +1,48 @@
name: Docs
on:
push:
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup V
run: |
wget -qO /tmp/v.zip https://github.com/vlang/v/releases/latest/download/v_linux.zip
unzip -q /tmp/v.zip -d /tmp
echo /tmp/v >> "$GITHUB_PATH"
- name: Build docs
run: |
v doc -f html -m .
pushd _docs
ln -vs dataunits.html index.html
ls -alFh
popd
- name: Upload static files as artifact
id: deployment
uses: actions/upload-pages-artifact@v3
with:
path: _docs/
deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
permissions:
contents: read
pages: write
id-token: write

24
.github/workflows/test.yaml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Tests
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup V
run: |
wget -qO /tmp/v.zip https://github.com/vlang/v/releases/latest/download/v_linux.zip
unzip -q /tmp/v.zip -d /tmp
echo /tmp/v >> "$GITHUB_PATH"
- name: Run tests
run: |
v -stats test .

2
.vdocignore Normal file
View File

@ -0,0 +1,2 @@
examples/
cmd/

View File

@ -1,23 +0,0 @@
SRC_DIR ?= src
DOC_DIR ?= doc
TESTS_DIR ?= .
all: test
test:
v test $(TESTS_DIR)
doc:
v doc -f html -m ./$(SRC_DIR) -o $(DOC_DIR)
serve: clean doc
v -e "import net.http.file; file.serve(folder: '$(DOC_DIR)')"
build:
v -path "$$(realpath $$PWD/../)|@vlib|@vmodules" \
-prod -parallel-cc -cflags -static -cflags -s -d no_segfault_handler \
cmd/dataunit -o dataunit
clean:
rm -r $(DOC_DIR) || true
rm dataunit || true

View File

@ -23,17 +23,12 @@
// For more information, please refer to <https://unlicense.org/>
/*
dataunit - a simple CLI tool for data units convertion.
*/
module main
import os
import flag
import dataunits
@[name: 'dataunit']
struct FlagConfig {
help bool
from string @[short: f]
@ -55,7 +50,7 @@ fn main() {
}
if flags.help {
println('convert the value between data size units.')
println('usage: dataunit -f <unit> -t <unit> <value>')
println('usage: datasize -f <unit> -t <unit> <value>')
println('options:')
println(' -help print this help message and exit')
println(' -f, -from source data unit')

View File

@ -18,8 +18,8 @@ fn (m Memory) mib() f64 {
fn Memory.from_string(s string) !Memory {
mut re := regex.regex_opt(r'^(\d+)([a-zA-Z]+)$')!
re.match_string(s)
if re.groups.len < 2 {
return error('unable to parse string ${s}')
if re.groups.len != 2 {
return error("unable to parse string '${s}'")
}
value := re.get_group_by_id(s, 0).f64()
unit := dataunits.from_string(re.get_group_by_id(s, 1))!

2
v.mod
View File

@ -1,7 +1,7 @@
Module {
name: 'dataunits'
description: 'Data units converter'
version: '0.0.1'
version: '0.0.2'
license: 'Unlicense'
dependencies: []
}