marcus

wireshell - an extendable ProcessWire command line interface

Recommended Posts

wireshell 1.0.0 is out   :) 

See Bea's post

Quote

 

wireshell 1.0.0  :)

Compatibility: ProcessWire 3.x

  • Prepares wireshell for ProcessWire 3.x, adds namespace support, only supports ProcessWire 3.x
  • Updates Github Repository: github.com/processwire/processwire
  • Improves module:upgrade command, if no argument is provided it just checks for upgrades
  • Extends new command, adds option --src=path/to/source to be able to use a pre-downloaded tgz/zip/folder
  • Extends status command, only shows database password if --pass option is provided, shows if an upgrade is available
  • Updates upgrade command, removes options dev and devns

 

 

wireshell.gif

-------- Original post -----------

 
Now this one could be a rather long post about only an experimental niche tool, but maybe a helpful one for some, so stay with me ;)
 
Intention
Do you guys know "Artisan" (Laravel) or "Drush" (Drupal)? If not: These are command line companions for said systems, and very useful for running certain (e.g. maintenance, installation) task quickly - without having to use the Admin Interface, first and foremost when dealing with local ProcessWire installations. And since it has a powerful API and an easy way of being bootstrapped into CLIs like this, I think such a tool has a certain potential in the PW universe. 
 
It's totally not the first approach of this kind. But: this one should be easily extendable - and is based on PHP (specifically: the Console component of the Symfony Framework). Every command is tidily wrapped in its own class, dependencies are clearly visible, and so on.
 
( Here was the outdated documentation. Please visit wireshell.pw for the current one )
  • Like 33

Share this post


Link to post
Share on other sites

Just as I'm in the means to build a separate directory for bugfixes, where I just paste in disposable processwire installations. Really great. Will certainly take a look at it later. I can also see this very useful for setting up base installations in a more flexible way than siteprofiles. 

  • Like 2

Share this post


Link to post
Share on other sites

Great! Thanks for this, Marcus. So far, everything looks good here on Windows - have only just installed PW-dev, going to work with other commands now. (Update: Everything works like a charm. Looking forward to seeing more Commands.)

For Windows users interested in making this global:

  1. Make sure PHP is in your PATH
  2. Create a wireshell folder somewhere (also added to your path), and create a wireshell.bat file:
@echo off
php "path\to\wireshell" %*

Then you can run wireshell new --dev anywhere you like.

  • Like 6

Share this post


Link to post
Share on other sites

Thanks for the positive feedback!

Some updates in 0.2.0:

  • Attach roles on the fly while user creation: $ wireshell create-user foo --roles=superuser,editor
  • Create templates and attach existing fields on the fly with $ wireshell create-template contact --fields=body,sidebar , prevent template file creation with --nofile
  • Command aliases now available: c-u, c-t, c-r, s

Now planning field creation. :)

  • Like 6

Share this post


Link to post
Share on other sites

Ever since I learned about drush I knew PW could benefit greatly from similar tool. Great job, Marcus!

Those "with dashes in-between" comands look a little weird for a cli interface. I saw you can easilly add aliases for commands, so maybe cr showd be included as a third one (as it is quicker to type)? Drush commands comprise of an object being manipulated followed by a "manipulation type". Not saying it is the right way to go, but it is better to choose some naming pattern explicitly.

Wireshell is a bit long too... Why not add an alias like ''wish" (for WIre SHell). It sounds magical, and isn't PW a wish come true?!

Thank you for developing this!

P.S. It kind of bugs me a little that this cli tool is written with symphony, not with PW itself. I am not even close to being able to argue here, but can it even be done?

  • Like 1

Share this post


Link to post
Share on other sites

Ever since I learned about drush I knew PW could benefit greatly from similar tool. Great job, Marcus!

Those "with dashes in-between" comands look a little weird for a cli interface. I saw you can easilly add aliases for commands, so maybe cr showd be included as a third one (as it is quicker to type)? Drush commands comprise of an object being manipulated followed by a "manipulation type". Not saying it is the right way to go, but it is better to choose some naming pattern explicitly.

Wireshell is a bit long too... Why not add an alias like ''wish" (for WIre SHell). It sounds magical, and isn't PW a wish come true?!

Thank you for developing this!

P.S. It kind of bugs me a little that this cli tool is written with symphony, not with PW itself. I am not even close to being able to argue here, but can it even be done?

Regarding aliases: Yeah, I'm aware of the dash, and wanted to try cr, cu, ct first, but in the case of "cr" Symfony Console bugged me with the following error:

Bildschirmfoto%202015-03-28%20um%2017.01

So in favor of consistency (cu. ct. cro?) I went for the dash.

As for "$ wish", that was also my first thought (especially regarding the pun), but I learned that - at least on Unix and OS X - there's a programm called "wish" already present (https://www.tcl.tk/)

/ Edit: and I'm totally open for a "command style standard". The current order "verb-noun" was nothing but a gut decision.

Edited by marcus

Share this post


Link to post
Share on other sites

Seems like you put the same alias for 3 commands...

Nope, but since the other two also start with cr.. Console component tends to misunderstand cr as an incomplete command.

Share this post


Link to post
Share on other sites

Not sure if this can be done with Symfony Console (I've never really looked at it before), but what about `create:user`, where a colon is used? I must be honest and say that I'm not one for short aliases - have always preferred concise, clear-cut naming. But, I'm sure others appreciate faster typing. ;-)

  • Like 2

Share this post


Link to post
Share on other sites

Not sure if this can be done with Symfony Console (I've never really looked at it before), but what about `create:user`, where a colon is used?

Good idea, totally possible and artisan-y. 

  • Like 1

Share this post


Link to post
Share on other sites

I'm being really silly - of course it's possible. Didn't even look at the source earlier. Simple as pie, like commands in Laravel.

Yeah, I just think that it gives a nice factory feel to it. Also, it makes the commands a tad easier to remember, considering there'll probably be quite a few as you go along.

Share this post


Link to post
Share on other sites

Hi all, 

With interest of everyone and love for Processwire, I will send a the PR to wireshell . So it will be a a one click installer.

  • Like 4

Share this post


Link to post
Share on other sites

Hi,

this tool is really cool idea. It would be great to have command for full PW installation, not just download. I've managed it by modifying original install.php file from PW 2.5 sources. But I'm not sure if it is production ready, it works but I haven't tested all edge cases. It requires config file with configuration array (db connection, profile, admin user credentials, ...). If you are interested I can post it somewhere. I plan to do it also for PW 2.4. With this comes and idea for 'new' command to allow installation of another versions other than the latest.

EDIT:

... So it will be a a one click installer.

Hari KT, don't you have the same intention? What do you mean by 'one click installer'. Installer for wireshell or for PW?

Share this post


Link to post
Share on other sites

@Richard: Hari KT said in his post he will send a PR (Pull Request) to WireShell. So it will be a one click step installer for WireShell, I think. :)

Share this post


Link to post
Share on other sites

Thanks for the proposals regarding an installer process, @HariKT and @Richard. A command named "new" definitely promises more than a download, that's right. But for this command I was just tipping my toe in the water, and testdriving the Console component, mimiking "laravel new" (which actually just is a download since there's no installation in the classic sense). Actually your thread about a command line installation of PW got me started with Wireshell in the first place :) So it's really cool that you'll contribute. Looking forward to the PR!

@Richard, it would be cool if you can post your approach to this. Frankly speaking I'm still in the learning phase regarding whats really possible with the API and would be glad if we could discuss in this thread the best approach about this - probably - most important command of Wireshell :)

 

  • Like 1

Share this post


Link to post
Share on other sites

Big update! Version 0.3.0 comes with:
 

  • a new "NewCommand" provided by HariKT! Big thanks again. This contribution should lead to a better workflow with Wireshell since it opens up the possibility to install PW via command line in a convenient way
  • A command for creating fields
  • A command for assigning fields to existing templates
  • A generic backup command (DB dump)
  • Commands for en/disabling modules (downloading them via Wireshell is still on my bucket list)
  • A little command outputting the currently installed ProcessWire version
  • An unified approach to naming commands and classes: entity:verb, so for example user:create
  • I dropped the "(Experimental)" from the topic's title  ;)

Read more about the available new commands and their options in the readme.

If you have an older version of Wireshell installed, make sure you "$ composer update" it in order to get the new dependencies. And we're on packagist now: https://packagist.org/packages/wireshell/wireshell
 

  • Like 14

Share this post


Link to post
Share on other sites

Great! Thanks for this, Marcus. So far, everything looks good here on Windows - have only just installed PW-dev, going to work with other commands now. (Update: Everything works like a charm. Looking forward to seeing more Commands.)

For Windows users interested in making this global:

  1. Make sure PHP is in your PATH
  2. Create a wireshell folder somewhere (also added to your path), and create a wireshell.bat file:
@echo off
php "path\to\wireshell" %*

Then you can run wireshell new --dev anywhere you like.

Since Wireshell is on packagist now and "composer global require wireshell/wireshell" installs it into "~/.composer/vendor/bin/wireshell" on Linux, could you test/check what the comparable Windows path or workflow would be? I'm currently rewriting (simplifying) the installation guide. Cheers!

  • Like 2

Share this post


Link to post
Share on other sites

On Windows, it installs to C:\Users\<user>\AppData\Roaming\Composer\vendor\wireshell\wireshell\ ... Not sure what the best way of making this global is, other than making a batch file look specifically in that directory. I must admit: I'm not a composer fundi, but I get the basics...

Update: In fact, if I run wireshell directly from the above directory (using php wireshell), it doesn't run because it's looking for vendor/autoload.php in that directory too. If I run the nasty php vendor/wireshell/wireshell/wireshell from the C:\Users\<user>\AppData\Roaming\Composer directory, it works. Phew, quite messy. But, like I said, I'm no fundi - there must be a better way to do this.

  • Like 1

Share this post


Link to post
Share on other sites

On Windows, it installs to C:\Users\<user>\AppData\Roaming\Composer\vendor\wireshell\wireshell\ ... Not sure what the best way of making this global is, other than making a batch file look specifically in that directory. I must admit: I'm not a composer fundi, but I get the basics...

Update: In fact, if I run wireshell directly from the above directory (using php wireshell), it doesn't run because it's looking for vendor/autoload.php in that directory too. If I run the nasty php vendor/wireshell/wireshell/wireshell from the C:\Users\<user>\AppData\Roaming\Composer directory, it works. Phew, quite messy. But, like I said, I'm no fundi - there must be a better way to do this.

Thanks so far! I discovered an installation guide for "laravel install" on windows: http://www.bitspedia.com/2014/09/how-to-install-and-make-first-laravel.html :

  1. Add your ~/.composer/vendor/bin path into Path environmental variable, so that Windows Command Prompt could identify laravel command that would be used later to install Laravel and doing other tasks. In my case the path where its located is: C:\Users\UserName\AppData\Roaming\Composer\vendor\bin 

    so I added it into my Path environmental variable. Must restart your Shell or Command-Prompt so that updated Path variables is loaded.

And when I googled "windows Path environmental variable", got this: http://www.computerhope.com/issues/ch000549.htm. This GUI/matrix seems to be the counterpart to .bashrc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      So I have a form, once completed, will create new pages. All in all, this is eazy-peezy for me now. I guess I need a bit of guidance on how to actually structure the rest of my code.  I thought I could just write a function (_func.php) and pass the fields to the function and let it do its' thing. However, I am kinda hitting a road block when I do it this way. 
      I currently am passing first name, last name, city, state (options field), and making pages based on the first/last names. I guess where I run into some issues is I am trying to check to see if the "page" already exists, and if it does, throw out an error:
      In the home template:
      if(isset( $_POST['submit'])) { $firstName =Trim (stripslashes($_POST['firstname'])); $lastName = Trim(stripslashes($_POST['lastname'])); $fullName = $firstName . $lastName; $city = Trim(stripslashes($_POST['city'])); $state = Trim(stripslashes($_POST['state'])); $lowerCaseName = strtolower($fullName); $people = $pages->find("template=person"); foreach ($people as $person) { $checkFirstName = $person->first_name; $checkLastName = $person->last_name; $checkFullName = $checkFirstName . $checkLastName; if ($checkFullName === $lowerCaseName) { echo "<p>" . "This person has already created a page. Please choose a different name." . "</p>"; } else { echo "hey"; processNewPerson(need_to_pass_person_details_to_function); } } // end foreach In _func.php:
      function processNewPerson($list) { $u = new Page(); $u->template = "person"; $u->parent = wire('pages')->get("/people/"); $u->title = ; $u->first_name = ; $u->last_name = ; $u->state = ; $u->city = ; $u->save(); $u->setOutputFormatting(false); } I am a little unsure of how to actually pass all the information to the template, as well as if this is even the best approach to do this. Would it make more sense to do this in a class, or keep it the way it is?
    • By louisstephens
      I have done a bit of searching, but I can not seem to find an actual answer. I have a list of services as child pages under "Services". I can output the services just fine, but I cant wrap my head around how to group them "alphabetically" like:
      Services A - Service "A" 1 - Service "A" 2 - Service "A" 3 B - Service "B" 1 - Service "B" 2 - Service "B" 3 C - Service "C" 1 - Service "C" 2 - Service "C" 3 Has anyone achieved this type of functionality before?
    • By quickjeff
      Hey guys, 
      Looking for another dev to help on multiple processwire projects as well as some other PHP apps. 
      First project is a directory style site with lots of components to come, including stripe implementation  and other fun stuff.
      Need someone ASAP to help out. 
       
      Thanks.
    • By louisstephens
      I am wondering, how do you pass a variable into wire('page')->get() inside a function? I have been looking through the forums, but unfortunately I have not found the answer yet.
      My current set up is:
      function generateNewPages($parentPageName) { $p = new Page(); $p->template = "parent"; $p->parent = wire('pages')->get('/home/'); $p->name = $parentPageName; $p->title = $parentPageName; $p->of(false); $p->save(); $p2 = new Page(); $p2->template = "child"; $p2->parent = wire('pages')->get('$parentPageName'); $p2->name = "child"; $p2->title = "Child Page"; $p2->of(false); $p2->save(); } When I try to run it by passing in a title like generateNewPages('Demo');, "Demo" is created, but when it gets to the child page I get:
      Unknown Selector operator: '$' -- was your selector value properly escaped?
      Is there a way to pass the $parentPageName to "wire('pages')->get('$parentPageName')" ?
    • By thomasaull
      I recently started to build Vue SPAs with ProcessWire as the backend, connected with a REST API. Thanks to code and the help of @LostKobrakai (How to use FastRoute with ProcessWire) and @clsource (REST-Helper) I got it up and running pretty quickly and now have put all of it in a site profile for others to use. It includes the REST API with routing for different endpoints, JWT Auth and a simple Vue SPA which shows the process of logging in a user (nevertheless, you don't have to use the Vue part, the API will work on it's own).
      Check it out here: https://github.com/thomasaull/RestApiProfile
      I'm pretty sure, it's not the perfect or most sophisticsted solution, but it gets the job done for me…
      Feedback or Improvements are very welcome
      Update: This site profile is a module now: https://github.com/thomasaull/RestApi