Let’s make a command line Sugar utility tool

Post originally written by Jesse.

When you work with something everyday, eliminating tedious and repetitive tasks not only improves your productivity but also helps your sanity. With Sugar, there are certain things we as developers are constantly doing; in some cases, over and over again. How many times have you run quick repair and rebuild?

Luckily, we program things. We write scripts that make our lives in that moment a tad bit easier. But it's easy to lose track of these things; we might even write the same tool over and over again.

In this series of posts, we're going to build a command line utility tool whose only purpose is to make life more beautiful. If you've ever used the laravel framework, you are familiar with the "artisan" tool which is built with the symfony console component. We are going to do the same thing.

The general idea here is to be able to call commands like these:

$ sugarcli admin:repair

$ sugarcli manifest:validate

Let's get started.

We are going to be using symfony console composer, so if you aren't familiar be sure to read-up on it. The first thing, we need to do is pull in our symfony console dependency in composer.json.

{

    "require": {

        "symfony/console": "v2.4.4"

    },

    "autoload": {

        "psr-4": {

            "Fbsg\\": "src"

        }

    }

}

$ composer install

Notice that we are using psr-4 for are auto-loading our classes, as we will be using psr compliant namespaces.

Now that we have our dependencies installed to the vendor folder, we are ready to start.

In the next post, we'll be building the quick repair/rebuild command.

You can view the github repository here.

Post From Faye Business Systems Group Director of Development Matthew Strickland

Contact Jesse Heller

  • Comment originally made by Joe.

    Hello,

    Once experienced Sugar dev/admin swinging by to check things out and hoping to maybe convince my current company how Sugar can make things better.

    Anyway, saw this thread and wanted to chime in that I think this is a FANTASTIC idea, and it's something I'd mentioned (somewhere... Twitter?) in the past. I'm a Drupal guy (Sugar's website is built with Drupal :) and Drush is a phenomenally useful tool. Quickly and easily run arbitrary scripts in a bootstrapped Drupal install, clear caches (drush cc all;) , download and install contrib, backup, stage, deploy, run updates and so much more. What a great project.

    Just a long-winded way of saying 'Let's do this!'

  • Comment originally made by Erwin Haasnoot.

    Sorry about resurrecting this thread. New Sugar developer here.

    I am wondering if there's any way to automate uploading a new version of a package/module in Sugar. I find the manual Upload in the "Module Loader" to be rather cumbersome and thus was hoping to get some tips on how to build a script that would allow me to run the uploading process directly from my IDE. (For example, some REST API functionality that would allow me to do just that).

    Thanks for reading! I'm looking forward to your input.

  • Comment originally made by Berend (@asciimen).

    A repair-rebuild is quite simple to do with Curl. With S7 things became a bit more complex with OAuth, but we've done this and adapted our script for Sgr7 to do a similar thing: repair-rebuild, rebuild roles perhaps. It also handles the vardef-change SQL.

    But its hardly more usable than that.

    What would be really handy: a CLI studio; like add-field, rename field...

    Or at least a CLI vardef schema extractor & validator ;-)

  • Comment originally made by Filipe Lopes.

    Looks great guys, can't wait to see it in action.
  • Comment originally made by John Spikowski.

    Wow! Seems like a lot of work. Wouldn't a simple SQL query do the trick?