Closed chicoxyzzy closed 2 months ago
This also still needs tests and docs update, but I wanted to start discussion earlier.
Ok, I think it's ready. I've also created a templates repo, please review it: https://github.com/dispatchrun/dispatch-templates
"dispatch init 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 propose user to update templates first."
Can we skip the question about updating templates and do it transparently to the user?
Yes, let's do it 👍
Looks like there's a test that's failing when I run it 🤔
$ make test
go build -o build/darwin/arm64/dispatch .
go test ./...
? github.com/dispatchrun/dispatch [no test files]
--- FAIL: TestRunCommand (0.34s)
--- FAIL: TestRunCommand/Run_with_env_variable_in_local_env_vars_has_priority_over_the_one_in_the_env_file (0.34s)
run_test.go:125: Expected printenv in the output: 2024/07/03 16:25:28 INFO loading environment variables from file path=/var/folders/qc/zv1mt0j11sscgjygfx47nxlm0000gn/T/TestRunCommandRun_with_env_variable_in_local_env_vars_has_priority_over_the_one_in_the_env_file1550241151/001/test.env
dispatch | 2024-07-03 16:25:28.027 starting session session_id=2tKgIdbajqVaIRM8ctdBcw
Error: command 'printenv CHARACTER' exited unexpectedly
Usage:
dispatch run [flags]
Flags:
-e, --endpoint string Host:port that the local application endpoint is listening on (default "127.0.0.1:8000")
-h, --help help for run
-s, --session string Optional session to resume
--verbose Enable verbose logging
Global Flags:
-k, --api-key string Dispatch API key (env: DISPATCH_API_KEY)
--env-file string Path to .env file
FAIL
FAIL github.com/dispatchrun/dispatch/cli 1.766s
FAIL
make: *** [test] Error 1
I'm curious whether we could leave the current directly as-is instead of removing all the files:
~/go/src/github.com/dispatchrun/dispatch/build/darwin/arm64 $ ./dispatch init python
Directory . is not empty. Do you want to overwrite it? [y/N]
y
Template python was created in /Users/achilleroussel/go/src/github.com/dispatchrun/dispatch/build/darwin/arm64
Even if we ask the user, removing their files seems like a dangerous choice to make... mistakes happen easily.
Another alternative could be to simply refuse to initialize a template in a non-empty directory, then we don't need to prompt them either.
Another alternative could be to simply refuse to initialize a template in a non-empty directory, then we don't need to prompt them either.
I agree. Fixed
Looks like there's a test that's failing when I run it 🤔
Weird. This is a test for the dispatch run
command. I don't think it's blocking for this PR, but I will take a look what's wrong here. It looks like printenv
is not installed on your device / OS.
It seems to be there:
$ which printenv
/usr/bin/printenv
I expect we would get a different error if the program wasn't found as well.
I've created a separate issue for the failing test and other dispatch run
improvements #80
This PR implements
dispatch init
command to initialize a new project.Usage
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
%APPDATA%
or%LOCALAPPDATA%
.$HOME/Library/Application Support
.$XDG_CONFIG_HOME or $HOME/.config
.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:
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
Try it
This will create
cat-facts
template in thedispatch-template-test
of your home directory. Note that build directory can be different for your computer's arch and OSTo clear templates cache
if you use MacOS
Notes and open questions
git clone
instead (althoughinit
's caching and templates updating features could be still useful)Shouldit's in the Dispatch groupdispatch init
go to theDispatch Commands
group or should it be in theAdditional Commands
in thedispatch -h
output?Closes #59