-
Notifications
You must be signed in to change notification settings - Fork 30
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
Improvements to run
and list
commands
#230
Conversation
The scope of the original ticket #229 is about parallel/multi-target changes, there wasn't green light for any other changes yet @christian-bromann. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really loving the UX changes, would love to see this implemented asap!
The runner-based implementation is also reasonable, though I do have some changes in mind. But the broad-strokes idea is good!
ctx, cancel := ctxWithSigCancel(cmd.Context()) | ||
defer cancel() | ||
inParallelMode := false | ||
blocks := os.Args[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an args
argument in the RunE
function. This will parse out all cli flags.
Do you think we can then use cobra's argument parsing facilities for the parallel/serial flags, and remove manual parsing?
cmd.Flags().BoolVarP(&runInParallel, "parallel", "p", false, "Run commands in parallel. (experimental)") | ||
cmd.Flags().BoolVarP(&runSequential, "sequential", "s", true, "Run commands sequentially. (experimental)") | ||
cmd.Flags().BoolVarP(&onlyCommandIO, "onlyCommandOutput", "", false, "If set, Runme will only output command output. (experimental)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cobra has StringSliceP
, which would allow for the following syntax:
runme run one two three -p four,five,six -s seven,eight,nine
Do you think that would be sufficient for this purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah totally! Nice
if blockID == "--experimental" { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot more valid flags than "--experimental" which you are not catching, which will presumably be run as blocks.
For example, running runme run -s a b c
tries to parse -s
as a code block
func (p *Project) ReadMarkdownFile(relativePath string, args []string) ([]byte, error) { | ||
absPath := path.Join(p.RootDir, relativePath) | ||
rootDir := path.Dir(absPath) | ||
fileName := path.Base(absPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (p *Project) ReadMarkdownFile(relativePath string, args []string) ([]byte, error) { | |
absPath := path.Join(p.RootDir, relativePath) | |
rootDir := path.Dir(absPath) | |
fileName := path.Base(absPath) | |
func (p *Project) ReadMarkdownFile(absPath string, args []string) ([]byte, error) { | |
rootDir := path.Dir(absPath) | |
fileName := path.Base(absPath) |
Why not use an absolute path? The relative option seems to make some other parts of the code a little cumbersome
p := project.New(fChdir) | ||
if !isInExperimentalMode() { | ||
filePath := path.Join(fChdir, fFileName) | ||
blocks, err := p.GetCodeBlocks(filePath[len(p.RootDir):], fAllowUnknown, fIgnoreNameless) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of filePath[len(p.RootDir):]
?
At any rate, one of the methods in filepath
would be much preferable rather than to do manual parsing...
|
||
ref, err := r.Head() | ||
func (p *Project) getAllMarkdownFiles() ([]string, error) { | ||
root, err := os.Getwd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root, err := os.Getwd() | |
root := p.RootDir |
if ref.Name().IsBranch() { | ||
return ref.Name().Short() | ||
fsys := os.DirFS(root) | ||
matches, err := fs.Glob(fsys, "**/*.md") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work as expected, and in particular will ignore files in the root directory.
You should probably use a WalkDir
-based solution instead.
if err != nil { | ||
return nil, errors.New("error while querying repository branches") | ||
for _, file := range files { | ||
codeBlock, err := p.GetCodeBlocks(file[len(p.RootDir):], false, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codeBlock, err := p.GetCodeBlocks(file[len(p.RootDir):], false, true) | |
codeBlock, err := p.GetCodeBlocks(file[len(p.RootDir):], allowUnknown, ignoreNameless) |
Should pass these down
select { | ||
case <-wgDone: | ||
// carry on | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This break does nothing since there is no surrounding loop
Co-authored-by: Max Stoumen <[email protected]>
Closing in favor of #236 |
According to our internal proposal this patch makes some changes to the
run
andlist
commands. These features are behind an environment flagRUNME_EXPERIMENTAL_CLI
. So the current behavior doesn't change. The new (experimental) CLI behavior works as following:list
command now lists all commands of all markdown files within a projectrun
command-p
or--parallel
flag to run a set of commands in parallelrunme run foo bar loo -p faz baz -s loo bar
will run:foo
,bar
andloo
sequentially, then will runfaz
andbaz
in parallel and lastlyloo
andbar
sequential againList Command Demo:
Screenshot of the WebdriverIO project based on
webdriverio/webdriverio#10237
Run Command Demo:
Reviewer Notes:
This patch basically does the following:
getCodeBlocks
orreadMarkdownFile
into the project modulegetAllMarkdownFiles
in the project module to find all markdown filesLookUpCodeBlockById
to find a block just by its name-s
for server address as it seems to be better suited (and more used) for providing the sequential flagOutstanding:
.gitignore
to not include markdown files matching these patterns (otherwise we would e.g. read from a bunch ofnode_modules
which would be quite overwhelming