Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken #17

Open
airtonix opened this issue Jun 21, 2024 · 2 comments
Open

broken #17

airtonix opened this issue Jun 21, 2024 · 2 comments

Comments

@airtonix
Copy link
Contributor

image

@airtonix
Copy link
Contributor Author

so the baseProfile is not broken. I forgot to set a jq version for my home folder using asdf.

@airtonix
Copy link
Contributor Author

airtonix commented Jun 29, 2024

just a follow up.

In my case ASDF creates shims for all the tools it manages.

Having a shim doesn't mean that a version of a tool is installed or configured to be used.

A tool can be configured via a .tool-versions file in the current directory or any parent directory up to the root of the current drive.

So in my case when there's no version of jq specified to use the output of jq is :

~ 
x command -v jq && echo "yes" || echo "no"
/home/zenobius/.asdf/shims/jq
yes

~ 
> jq
No version is set for command jq
Consider adding one of the following versions in your config file at /home/zenobius/.tool-versions
jq 1.7.1

~ 
x which jq
~/.asdf/shims/jq

~ 
> asdf global jq 1.7.1

~ 
> command -v jq && echo "yes" || echo "no"
/home/zenobius/.asdf/shims/jq
yes

~ 
> which jq                                
~/.asdf/shims/jq

~ 
> jq
jq - commandline JSON processor [version 1.7.1]

Usage:  /home/zenobius/.asdf/installs/jq/1.7.1/bin/jq [options] <jq filter> [file...]
        /home/zenobius/.asdf/installs/jq/1.7.1/bin/jq [options] --args <jq filter> [strings...]
        /home/zenobius/.asdf/installs/jq/1.7.1/bin/jq [options] --jsonargs <jq filter> [JSON_TEXTS...]

jq is a tool for processing JSON inputs, applying the given filter to
its JSON text inputs and producing the filter's results as JSON on
standard output.

The simplest filter is ., which copies jq's input to its output
unmodified except for formatting. For more advanced filters see
the jq(1) manpage ("man jq") and/or https://jqlang.github.io/jq/.

Example:

        $ echo '{"foo": 0}' | jq .
        {
          "foo": 0
        }

For listing the command options, use /home/zenobius/.asdf/installs/jq/1.7.1/bin/jq --help.

~ 
x 

So perhaps the best way to ensure required commands are installed and available isn't through a map of names, but instead through a function that just steps through manual checks of the command output:

#!/bin/bash

requires_command() {
    local input
    local name
    local pattern 

    input="$(cat)"
    name="$1"
    pattern="$2"

    # first use command to test if the command exists
    command -v "$name" > /dev/null || {
        echo "Command '$name' not found. Please install it."
        exit 1
    }

    # then use grep to test the output
    echo "$input" | grep -q "$pattern" || {
        echo "Command '$name' exists, but didn't match expected output."
        exit 1
    }

}


# pass the output of `jq --version` through a pattern to test the output

dependancies() {
  jq --version | requires_command 'jq' 'jq-1\.[0-9]\+'
  some_other_command_ctl -v | requires_command 'some_other' 'some other command output: 34\.[0-9]\+'
  etc | requires_command 'etc' '*'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant