dispatchrun / dispatch

Entrypoint of the Dispatch ecosystem.
11 stars 1 forks source link

add `dispatch init` command #78

Closed chicoxyzzy closed 2 months ago

chicoxyzzy commented 2 months ago

This PR implements dispatch init command to initialize a new project.

Usage

dispatch init <template> [path]

Where <template> is a required option and [path] is optional.

Templates directory

On a first use the command will create an Application Data directory dispatch

The App Data directory is used to save templates oh a user's computer to make them available for use later without Internet. The directory has follows structure:

dispatch/
  templates/
    foo/
    bar/
  templates.sha

Workflow

1) dispatch init <template> will try to get the SHA of the latest commit from the repository and compare it to local SHA. If values differ, Dispatch CLI will download update for templates first. 2) Dispatch CLI makes request to using GitHub REST API to download tarball of the latest commit and then extracts it into the Dispatch's App Data directory. 3) Finally, it copes template's files from the App Data directory (provided as <template> option) to a current working directory or to the [path] if it was provided.

If the destination directory is not empty, user will be asked if they want to clear the directory

image

Try it

git checkout init_command
make build
./build/darwin/arm64/dispatch init cat-facts ~/dispatch-template-test

This will create cat-facts template in the dispatch-template-test of your home directory. Note that build directory can be different for your computer's arch and OS

To clear templates cache

rm -rf ~/Library/Application\ Support/dispatch

if you use MacOS

Notes and open questions


Closes #59

chicoxyzzy commented 2 months ago

This also still needs tests and docs update, but I wanted to start discussion earlier.

chicoxyzzy commented 2 months ago

Ok, I think it's ready. I've also created a templates repo, please review it: https://github.com/dispatchrun/dispatch-templates

vadimdemedes commented 2 months ago

"dispatch init