Choose download directory

Hello there, first of all, thanksa lot for being available on this platform for studying many programming languages. It’s awesome.

So, I saw on closed issues this request #916, and I will bring another point of view. I have three different tracks on exercism. If I configure workspaces, all downloads will still be in an unique directory.

Is it possible to use a new flag, such as --directory, to choose as a directory at the time of downloading?

 exercism download --track=python --exercise=little-sisters-essay --directory=/my/custom/directory/python
 exercism download --track=ruby --exercise=little-sisters-essay --directory=/my/custom/directory/ruby
 exercism download --track=go --exercise=little-sisters-essay --directory=/my/custom/directory/golang

exercism download --track=python --exercise=little-sisters-essay --directory=/my/custom/directory/python

is unclear on where the exercise files are actually being saved to. Would I be downloading the exercise files directly into the folder at /my/custom/directory/python? If not, is the exercism CLI creating a little-sisters-essay folder at that location and stashing the files there? What happens if the user already has the exercise slug in the folder path? I may not have wanted a little-sisters-essay folder inside another little-sisters-essay folder.

It should be fairly simple to write a wrapper script that sets the workspace path for you, too. It’s not as clean but it’s a simple work around. A symlink is another rather simple way to get that setup.

It seems like you want this:

exercism configure --workspace /my/custom/directory

Then, when you say

exercism download --track=python --exercise=little-sisters-essay

you’ll get /my/custom/directory/python/little-sisters-essay

go is the outlier, but you can do

cd  /my/custom/directory
mkdir go
ln -s go golang

Then exercism download -t go -e little-sisters-essay will create the new exercise directory in /my/custom/directory/go but you can access it via the symlink.

1 Like

Hello everyone, so sorry if I’m not clear in my request, but I was thinking of a way to create a custom directory when I get a new exercise. As I say, I have 3 tracks, and I need to move the exercise to a different folder all the time when I do a new download to organize the tracks

As Isaac suggested, a wrapper script:

function exercism () {
    case $1 in
        download) exercism_download "${@:2}" ;;
        *)        command exercism "$@" ;;
    esac
}

function exercism_download () {
    getopt -T >/dev/null 2>&1
    if (( $? != 4 )); then
        echo "I require GNU getopt"
        return 1
    fi

    # https://salsa.debian.org/debian/util-linux/-/blob/debian/unstable/misc-utils/getopt-example.bash

    local tmp
    if ! tmp=$(getopt -o 't:e:h' --long 'track:,exercise:,help' -n exercism -- "$@"); then
        return 1
    fi

    eval set -- "$tmp"

    local track exercise
    while true; do
        case $1 in
            -h | --help)
                command exercism download --help
                return
                ;;
            -e | --exercise)
                exercise=$2
                shift 2
                ;;
            -t | --track)
                track=$2
                shift 2
                ;;
            --) shift
                break
                ;;
            *)  echo "Internal error" >&2
                return 2
                ;;
        esac
    done

    if [[ -z $exercise ]]; then
        command exercism download --help
        return 1
    fi

    local download_args=( -e "$exercise" )
    local workspace

    if [[ -n $track ]]; then
        download_args+=( -t "$track" )
        workspace=$(command exercism workspace)

        case $track in
            go)     command exercism configure -w /my/golang/directory ;;
            python) command exercism configure -w /my/python/directory ;;
            # etc
        esac
    fi

    command exercism download "${download_args[@]}"
    local status=$?

    # restore the previous workspace
    [[ -n $track ]] && command exercism configure -w "$workspace"

    return "$status"
}

If you want to configure a per-track directory, that is trivial via symlinks. Set up a ~/.config/exercism/tracks as your workspace then put the per-track symlink there that tells the CLI where you want each track to be downloaded.

mkdir ~/.config/exercism/tracks
exercism configure -w ~/.config/exercism/tracks
ln -s /python/stuff/here ~/.config/exercism/tracks/python
ln -s /golang/stuff/here ~/.config/exercism/tracks/go

If you want each exercise to go somewhere unique, you could use symlinks (similar to the directories above) or a wrapper (similar to what Glenn posted). I’m not sure that really lines up with the intended or general use case of the CLI.

If I understand the OP correctly, they want to merge all languages into one directory per exercise. That is a bad idea as each language can have different README contents for the same exercise - a lot of confusion ahead…