Hacker News new | ask | show | jobs
by nadaviv 1182 days ago
GPT is pretty good at figuring out argument parsing code based on example CLI usage. Like this:

    > Write bash code to parse the following arguments:
    >
    > $ ./export.sh --out-file dump.json --db foo.sqlite --include-headers --exclude-rev -vvv -p9000

    Here's an example bash code to parse the arguments:

    #!/bin/bash

    # Default values for optional arguments
    INCLUDE_HEADERS=false
    EXCLUDE_REV=false
    VERBOSE_LEVEL=0
    PORT=0

    # Parse the arguments
    while [[ "$#" -gt 0 ]]; do
        case $1 in
        --out-file) OUT_FILE="$2"; shift ;;
        --db) DB="$2"; shift ;;
        --include-headers) INCLUDE_HEADERS=true ;;
        --exclude-rev) EXCLUDE_REV=true ;;
        -v) VERBOSE_LEVEL=$((VERBOSE_LEVEL+1)) ;;
        -p) PORT="$2"; shift ;;
        -h|--help) 
            echo "Usage: ./export.sh [OPTIONS]"
            echo ""
            echo "Options:"
            echo "--out-file     Output file path (required)"
            echo "--db           Database path (required)"
            echo "--include-headers  Include column headers in output (default: false)"
            echo "--exclude-rev   Exclude revisions in output (default: false)"
            echo "-v              Increase verbosity level (default: 0)"
            echo "-p              Port number (default: 0)"
            echo "-h, --help      Show help"
            exit 0
            ;;
        *) echo "Unknown parameter passed: $1"; exit 1 ;;
        esac
        shift
    done

    # Check required arguments
    if [[ -z $OUT_FILE ]]; then
        echo "Error: missing argument --out-file"
        exit 1
    fi

    if [[ -z $DB ]]; then
        echo "Error: missing argument --db"
        exit 1
    fi

    # Print parsed arguments
    echo "OUT_FILE=$OUT_FILE"
    echo "DB=$DB"
    echo "INCLUDE_HEADERS=$INCLUDE_HEADERS"
    echo "EXCLUDE_REV=$EXCLUDE_REV"
    echo "VERBOSE_LEVEL=$VERBOSE_LEVEL"
    echo "PORT=$PORT"
2 comments

Honestly nobody cares. It's insulting to every reader to post this kind of crap.
Why is it insulting to point out that GPT can produce good results for this particular use-case?

Being able to define your argument types and generate parsing code for them using an example CLI invocation feels very natural and expressive to me. I personally found it to be useful for my work.

I wish it was crap, then I could pretend I'm participating in some form of modern performance art. This is, unfortunately, just propaganda.
Wait what? Propaganda? I really don't get why this is invoking such strong reactions...
He's saying the code isn't crap and the attack on it is propaganda. The reason for the strong reactions is pretty simple. The majority of people here program for a living and GPT is a threat to their income.
I doubt anyone who codes professionally is threatened by kids posting chatbot output. There's a widening gap between actual knowledge and people who think they know something because they can regurgitate it. It's exactly like people who think they know about something because they can look it up on the internet. They're super annoying but completely nonthreatening
This is actually very close to what I write manually; I've never been a fan of getopts syntax since you need to do the loop and case anyway.