From 4112bfaecdf323948459aef525d36c37c102531b Mon Sep 17 00:00:00 2001 From: Tadej Panjtar Date: Wed, 3 Apr 2024 07:07:39 +0200 Subject: [PATCH] In CI added windows_latest, help added and array margin checking. --- .github/workflows/CI.yml | 43 ++++++++++++++++++++++++++++++++++ .github/workflows/blank.yml | 46 ------------------------------------- src/cht.v | 23 +++++++++++++++---- src/cht_colors_windows.c.v | 8 ++++--- test/options_test.v | 46 +++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .github/workflows/blank.yml create mode 100644 test/options_test.v diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..bb1f57b --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,43 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "master" branch + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + build: + strategy: + matrix: + os: ["ubuntu-latest", "windows-latest"] + runs-on: ${{ matrix.os }} + + steps: + - name: Install V + uses: vlang/setup-v@v1 + with: + check-latest: true + + - name: Checkout ${{ github.event.repository.name }} + uses: actions/checkout@v2 + +# Does not check format since works different under different OS +# - name: Check if code is formatted +# run: | +# v fmt -diff . +# v fmt -verify . + + - name: Build ${{ github.event.repository.name }} + run: v . -o cht + + - name: Run Tests + run: v test . diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml deleted file mode 100644 index e4dfc91..0000000 --- a/.github/workflows/blank.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the "master" branch - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-22.04 #ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - .github/workflows/retry.sh sudo apt-get update - .github/workflows/retry.sh sudo apt-get install --quiet -y build-essential libcurl4 libcurl4-openssl-dev - - name: Download V - run: | - tag="latest" - .github/workflows/retry.sh wget https://github.com/vlang/v/releases/$tag/download/v_linux.zip - unzip v_linux.zip - cd v - ./v -version - - name: Compile - run: | - cd v - ./v ../src -o ../cht - - - name: Test cht - run: ./cht --version - diff --git a/src/cht.v b/src/cht.v index e4411c5..ce259ec 100644 --- a/src/cht.v +++ b/src/cht.v @@ -2,7 +2,7 @@ import net.http import os import os.cmdline -const cht_version := '0.7.0' +const cht_version := '0.7.2' fn main() { @@ -27,16 +27,29 @@ fn main() { '-Q', '--query' { use_query = true } - '-l' { domain = cmdline.option(os.args, '-l', '') + '-l' { + domain = cmdline.option(os.args, '-l', '') qs += domain.str() qs += '/' } - '-v', '--version' { println('cht version ' + cht_version + ' (c) Tadej Panjtar') + '-V', '--version' { + println('cht version ' + cht_version + ' (c) Tadej Panjtar') exit(0) } - else { println ('Unknown option: ' + opt) + '-h', '--help' { + println('\nUsage: cht [options...] ') + println('Options:') + println(' -Q, --query Space delimited arguments are parts of query (now default)') + println(' -T, --no_colors Disabling coloring globally') + println(' -V, --version Show version and exits') + println(' -TA,--force_ansi_colors Force ANSI colors') + println(' -l Domain language set') exit(0) } + else { + println('Unknown option: "${opt}"') + exit(1) + } } } @@ -49,7 +62,7 @@ fn main() { } first_handeled = true } - qs = qs.trim('+') + qs = qs.trim('+/') // Dummy usage to get rid of warnings if use_query { diff --git a/src/cht_colors_windows.c.v b/src/cht_colors_windows.c.v index 69251e8..ea4088c 100644 --- a/src/cht_colors_windows.c.v +++ b/src/cht_colors_windows.c.v @@ -62,7 +62,7 @@ fn println_colored(s string, use_colors bool, force_ansi_colors bool)! { if str_first>0 { for i :=0; i