Skip to content
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

[Refactor] Move command runner to common #63

Open
8 tasks
at15 opened this issue Dec 20, 2016 · 5 comments
Open
8 tasks

[Refactor] Move command runner to common #63

at15 opened this issue Dec 20, 2016 · 5 comments

Comments

@at15
Copy link
Member

at15 commented Dec 20, 2016

currently, only part of the runner code is in util/runner, also command.go is coupled with viper, and I plan to split it out like the log package #59, so it can be used in other projects.

@at15 at15 added this to the 0.1.0 milestone Dec 20, 2016
@at15 at15 self-assigned this Dec 20, 2016
@at15 at15 mentioned this issue Dec 20, 2016
3 tasks
@at15
Copy link
Member Author

at15 commented Dec 20, 2016

actually the runner is highly coupled with viper, so move it non trivial, but the util/command.go can be moved easily

@at15
Copy link
Member Author

at15 commented Dec 21, 2016

also may need sth like a context, in order to extend for things like run using shell instead of os/exec, though forcing the user to write /bin/sh -c "rm *.aux" is also an approach. context can also be used to do things like npm, where user defined tasks can be reused.

@at15
Copy link
Member Author

at15 commented Dec 21, 2016

About the register command dynamically on cobra,

cobra.OnInitialize does not work, because if you look at the code, it add the function to initializer which is executed in preRun, so it only works when certain command is invoked, help is a command, so help would show the added dummy command, but run Ayi dummy would have error.

Adding things in init will work for sure, but config files are not loaded and flags are unknown at that time

However, since cobra is executed only when RootCmd.Execute is called, dynamic adding command can be added in the wrapper. But there is still a problem, are those global flags already usable? I guess so? .... somewhere in the code, the parse for pflag should be called.

@at15
Copy link
Member Author

at15 commented Dec 21, 2016

the fallback is, for Ayi, always read these default config files and generate dynamic commands ... actually it's quite overkill

@at15 at15 modified the milestones: 0.0.4, 0.1.0 Dec 22, 2016
@at15
Copy link
Member Author

at15 commented Dec 31, 2016

Ansible provide a good example, http://docs.ansible.com/ansible/playbooks_intro.html

tasks:
  - name: run this command and ignore the result
    shell: /usr/bin/somecommand
    ignore_errors: True

Actually Ayi's intention is quite like Ansible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant