silverleague / silverleague.github.io

The home of the SilverLeague
http://silverleague.github.io
1 stars 1 forks source link

Proposal: silverstripe-console #1

Closed robbieaverill closed 6 years ago

robbieaverill commented 7 years ago

silverleague/silverstripe-console

Repository: https://github.com/silverleague/silverstripe-console Specification: https://silverleague.github.io/development/silverstripe-console

Introduction

The SilverLeague Console is a Symfony console application which interfaces directly with a SilverStripe application for a better command line experience.

Use case

The SilverStripe framework ships with a built in CLI management tool - "framework/cli-script.php". It also has a bash wrapper called "sake". This tool essentially lets you run controllers from the command line in much the same way as you would from the browser, while providing added benefits such as not having to worry about web server timeouts, being able to run in a cron task, etc.

This tool is limited. The SilverLeague console aims to replace its use with a more powerful, flexible and featured tool for managing SilverStripe applications.

Aims over other community modules

There are some existing CLI modules for SilverStripe among the community already. This module is going to be built with the following focusses:

This module would not support SilverStripe 3.x at this stage. Users would be recommended to use an established console like "supersake" for legacy framework/CMS support.

Functionality

License

To be released under the MIT license.

Firesphere commented 7 years ago

Sorry, I would prefer @axyr his work here. His console module is way more complete and stable and provides a coherent CLI interface.

dmc-core commented 7 years ago

Debugging output and the ability to completely delete pages would be a nice touch!

robbieaverill commented 7 years ago

Thanks @dmc-core - I've adjusted your suggestions to be for DataObjects generally instead of Pages. Great idea.

dmc-core commented 7 years ago

Thinking about the db and assets export/imports could we utilise sspak as a requirement and wrap it in its own namespace? Could then pass in its expected args etc from the single cmd. Ie sspak:load [args]

robbieaverill commented 7 years ago

@dmc-core I like that. It would remove our database and assets command scope, and we add sspak as a command namespace which is literally a wrapper for sspak, which can be included with composer and bootstrapped accordingly

sminnee commented 7 years ago

How does this compare to https://github.com/axyr/silverstripe-console?

robbieaverill commented 7 years ago

The comparison is very similar.

I think what this proposal is trying to achieve that other consoles (cli-script/sake, supersake and sakemore), as well as sspak etc, don't already can be loosely summed up as:

The general ideas of SilverLeague in terms of high quality code, exhibiting best practices for development/architecture, high test coverage etc apply too, but aren't necessarily unique to this console versus the others.


Those are pretty high level, but on a granular level, one thing this module does that supersake doesn't is the ability to see all native SS tasks and run them.

sminnee commented 7 years ago

This is not a SilverStripe module, it's a utility (do not install into the web root or the SilverStripe framework) - you install globally with composer, or we potentially compile a phar at some stage - especially since the global Symfony Console requirement conflicts with that of the upgrader tool (if installed globally as well)

Yeah, it's difficult (but not impossible) to make a single package that combines both use-cases. I would probably note that the approach of other tools such as phpunit has been do go the other way, and notably in SS4 you can't use the globally installed version. We've chosen this approach for a number of reasons:

To that effect, in SS4 I was keen to see both silverstripe/serve get a bit more love as a recommended dev tool, and for sake to be replaced with something provided by a separate project-specific dependency, that puts a binary into vendor/bin.

robbieaverill commented 7 years ago

Yeah - this module will run as a project dependency (as the others do too) and that would mean less magic for adapting multiple major SS versions in one app and instead just installing the appropriate tag for your SS version. I personally prefer tools like this to be separate from the codebase, but can see the benefits of having it bundled in with it too

sminnee commented 7 years ago

Presumably you might have extensions to the CLI tool that only apply to a given project. In these cases it would make sense to have the extension loaded into the project rather than globally.

You might set up an architecture where if the global tool detects that the in-project tool is installed, it defers all the commands to it. That could potentially leave the global tool quite lean, and make a cross-major-version tool more feasible without a bunch of if blocks.

robbieaverill commented 7 years ago

True. You could also have a global utility that looks for local modules

axyr commented 7 years ago

That would over complicate things...

What about commands I want to use on production?

robbieaverill commented 7 years ago

I guess if you have production ssh access then you would also have access to install a utility into the path. As I say though, this can currently be installed as a silverstripe dependency as well, it's just that I'd encourage against it :-)

robbieaverill commented 7 years ago

For reference, the Magento equilavent (which I'm trying to model this on) n98-magerun doesn't appear to encourage installation inside a Magento project, nor augment any functionality within the app (like admin interfaces). I'm not sure whether than means you couldn't install it as a composer dependency at all though

axyr commented 7 years ago

Checkout Laravel. There are tons of use cases you want have console commands on production.

I have several website spiders that are solely ran from scheduled commands.

Or scheduled mailers, maintenance scripts etc. Putting a site in 503.

So if I have 1 site that needs console commands, I need to install a tool global that could otherwise just als easy added as a composer dependency with the correct tag that I require for that project?

robbieaverill commented 7 years ago

You completely can install into your project if it suits your use case

sminnee commented 7 years ago

It might be helpful to elaborate on what you see as the biggest benefits of installing the tool globally. Is it about easy execution, smaller project size, ability to run commands such as "create project" that don't naturally fit into a single project, or something else?

robbieaverill commented 7 years ago

Here's what I see as the pros and cons of both ways:

Global install

Pros

Cons

In-project

Pros

Cons


Both install options would be able to support local extensions to the application (within the project, or user's home folder in the environment, or both).

I think that the "preferred installation option" would probably guide a decision like "should we support multiple SilverStripe framework versions in a single app, or have different versions for each" - since you don't need the added complexity of the former if you're deploying natively into a project, and you probably do if you deploy globally.

Otherwise, I think it's largely going to come down to the preference of the developer using it - the tool supports both options already. It'd be good to choose a little more definitely which way to go, which will naturally guide the decision mentioned above re: version support.

I'm already pretty indifferent - if people want to install it into a project, that's cool, if they want to install it globally, that's fine too.

Firesphere commented 7 years ago

Can you get a comparison between @axyr his work and yours? This still feels to me as a "I did this, so take mine" over "This is the best solution".

robbieaverill commented 7 years ago

"I did this, so take mine" over "This is the best solution".

It's not like that - there wasn't a suitable module for what I wanted to do (outlined previously), and the existing consoles (there are many, not just one) aren't on offer here.

I'm mostly dubious of reinventing wheels, which is why I've tried to propose a substantial set of improvements over what any of the others offer.

robbieaverill commented 6 years ago

1.0.0 tagged, not all of the initial features made it in but it's got some useful ones.