Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

CLI-next #134

Closed
wants to merge 83 commits into
from

Conversation

Projects
None yet
9 participants
Owner

wfarr commented Nov 26, 2013

WORK IN PROGRESS, DO NOT MERGE

Refactor all the things to eliminate all of the painful parts of dealing with the Boxen gem, like:

  • everything running every preflight check, when it's not even necessary
  • the complete and utter lack of real subcommands
  • no good way for people to hook their own subcommands into Boxen easily

TODO

  • a whole lot

/cc @dgoodlad @jbarnette

boxen.gemspec
+lib = File.expand_path("./lib", File.dirname(__FILE__))
+$:.unshift lib
+require "boxen/version"
+
@jbarnette

jbarnette Nov 26, 2013

Contributor
load "lib/boxen/version.rb"
lib/boxen/commands/command.rb
+
+module Boxen
+ module Commands
+ class Command
@jbarnette

jbarnette Nov 26, 2013

Contributor

I think Boxen::Command is a better name than Boxen::Commands::Command.

lib/boxen/commands/command.rb
+ module Commands
+ class Command
+
+ class << self
@jbarnette

jbarnette Nov 26, 2013

Contributor

I always prefer self. for grepability.

lib/boxen/commands/command.rb
+ class Command
+
+ class << self
+ def preflight(*klasses)
@jbarnette

jbarnette Nov 26, 2013

Contributor

All this goes away if there's a:

def preflights
  @preflights ||= []
end

Same for postflights.

@jbarnette

jbarnette Nov 26, 2013

Contributor
def preflight(*klasses)
  preflights.replace preflights | klasses.flatten
end

...or however you feel like dealing with dups and nesting. 😄

@wfarr

wfarr Nov 26, 2013

Owner

I'm not sure the first thing works, if I interpreted you correctly.

class Foo
  def self.preflight(*args)
    preflights += args
  end

  def self.preflights
    @preflights ||= []
  end
end
irb(main):010:0> Foo.preflight "bar"
NoMethodError: undefined method `+' for nil:NilClass
    from (irb):3:in `preflight'
    from (irb):10
    from /opt/boxen/rbenv/versions/2.0.0-github/bin/irb:12:in `<main>'
lib/boxen/commands/command.rb
+ end
+
+ def run
+ raise NotImplementedError
@jbarnette

jbarnette Nov 26, 2013

Contributor

Careful. It doesn't mean what it says it means. I really only care because it doesn't inherit from StandardError and that can be confusing as shit.

lib/boxen/commands/command.rb
+ @args = args
+ end
+
+ def invoke
@jbarnette

jbarnette Nov 26, 2013

Contributor

Seems like having run be the public API would be better name-wise.

@wfarr

wfarr Nov 26, 2013

Owner

run is currently what a command defines as what it should run.

invoke is only used internally.

Owner

dgoodlad commented Nov 27, 2013

Current --help output:

Usage: boxen [options] [projects...]

        --debug                      Be really verbose.
        --pretend, --noop            Don't make changes.
        --report                     Enable puppet reports.
        --env                        Show useful environment variables.
    -h, -?, --help                   Show help.
        --disable-service SERVICE    Disable a Boxen service.
        --enable-service SERVICE     Enable a Boxen service.
        --restart-service SERVICE    Restart a Boxen service.
        --disable-services           Disable all Boxen services.
        --enable-services            Enable all Boxen services.
        --restart-services           Restart all Boxen services.
        --list-services              List Boxen services.
        --homedir DIR                Boxen's home directory.
        --logfile DIR                Boxen's log file.
        --login LOGIN                Your GitHub login.
        --no-fde                     Don't require full disk encryption.
        --no-pull                    Don't try to update code before applying.
        --no-issue, --stealth        Don't open an issue on failure.
        --token TOKEN                Your GitHub OAuth token.
        --profile                    Profile the Puppet run.
        --future-parser              Enable the Puppet future parser
        --projects                   Show available projects.
        --srcdir DIR                 The directory where repos live.
        --user USER                  Your local user.
        --no-color                   Disable colors.
Owner

wfarr commented Nov 27, 2013

A brief exploratory session via documentation follows. /cc @jbarnette and @ymendel for taste.

~/github/boxen system » boxen help
    help             Displays help, obviously
    version          Displays the current version of Boxen
    run              run Boxen's managed puppet environment
    project          Show and manage projects.
    service          Show and manage Boxen services.

~/github/boxen system » boxen help help

    boxen help [<command>]

        With no arguments, displays short help information for all commands.

        Given a command name as an argument, displays detailed help about that command.

~/github/boxen system » boxen help version

    boxen version

        Display the current version of the Boxen gem.

~/github/boxen system » boxen help run

    boxen run [options]

        Runs Puppet via Boxen's environment.

        Some options you may find useful:

            --debug                 Be really, really verbose. Like incredibly verbose.
            --no-issue              Don't file an issue if the Boxen run fails.
            --no-color              Don't output any colored text to the tty.
            --report                Generate graphs and catalog data from Puppet.
            --profile               Display very high-level performance details from the Puppet run.

    boxen run:noop [options]

        The same thing as run, but acts as a dry run where no changes are made.

~/github/boxen system » boxen help service

    boxen service

        Display all services Boxen knows about.

    boxen service:enable <service1> [<service2> ...]

        Enable and start a Boxen-managed service.

    boxen service:disable <service1> [<service2> ...]

        Disable and stop a Boxen-managed service.

    boxen service:restart <service1> [<service2> ...]

        Disable and stop a Boxen-managed service.

    boxen service:enable_all

        Enable all Boxen-managed services.

    boxen service:disable_all

        Disable all Boxen-managed services.

    boxen service:restart_all

        Restart all Boxen-managed services.

Still playing around with the UI for project, so not featuring that just yet.

Owner

wfarr commented Nov 27, 2013

BTW, all of the above is actually working on my machine ATM.

Contributor

jbarnette commented Nov 27, 2013

This looks awesome. Boxen with no subcommand defaults to run?

Owner

wfarr commented Nov 27, 2013

This looks awesome. Boxen with no subcommand defaults to run?

That's the intent for now, yes.

The addition of the project subcommand when that rolls around will make for a bit of breakage, as boxen <projectname> will go away. But if my concept for the project subcommand comes together, I don't think anyone will mind terribly.

Contributor

jbarnette commented Nov 27, 2013

💥🐫

Owner

wfarr commented Nov 28, 2013

Rough outline for the world of project subcommands, looking for some feedback:

    boxen project

        Display all projects Boxen knows about.

    boxen project:add <project1> [<project2> ...]

        Adds the projects to your personal configuration.

    boxen project:remove <project1> [<project2> ...]

        Removes the projects from your personal configuration.

    boxen project:new <path>

        Helps you create a project manifest for the project at path.

project:add and project:remove

How do we store the state for these?

Hierdata.

Continuing with some work @dgoodlad has done recently, we can continue overloading hiera as a general YAML store we can act upon. Add and remove then simply load this file in, parse the YAML, make changes to the hash, and write the data back out.

We already have Hiera files like this in our fork in hiera/users/${github_login}.yaml. We can make this pattern a bit more official, because Hiera's legitimately awesome for things like per-user overrides of parameters and people should make use of this:

---

"personal":
  "projects":
    - "github"
    - "play"

In Puppet, we then, have a new Puppet::Parser::Function called include_projects_from_hiera(). In short pseudocode form, this does something like the following to inject them into the catalog at parse time:

function_hiera_lookup("person")["boxen::projects"].each do |p|
  function_include("projects::#{p}")
end

This starts to set the trend I want for enabling users to customize their Boxen configuration a fair bit of the way without requiring any knowledge of Puppet — we can generally assume that most folks are comfortable with either YAML or JSON (we can support both with Hiera). There are other plans to extend this same "personal" key in Hiera with things like packages, etc.

project:new

This idea comes from @dgoodlad. The short of it is a Q/A style walkthrough for creating a project manifest.

Let's mock out on example:

~ $ boxen new src/rubygems.org

New project time, eh? Let's get crackin'! Just give me a moment to scan through your project and see if I can figure out what you need...

I found a Gemfile that says you need Ruby "1.9.3". Anything more specific? [1.9.3]

Your Gemfile also shows you're using Redis. Sound right? [Y/n]

Your Gemfile also shows you're using MySQL. Should Boxen make sure that's installed for you? [Y/n]

Are there any extra system packages your project needs? (Hit 'Return' twice when you're done listing them)

icu4c
ghostscript


And what should we call this project? [rubygems-org]

Awesome. I've created a project definition at ~/src/boxen/modules/projects/manifests/rubygems-org.pp.

Be sure to commit it and push it up so the rest of your posse can hack on it too!

For now this generates existing Puppet code. In the future, we overload Hiera like we're doing for personal customizations now and use it as a way of making project definitions dynamically.

Owner

fromonesrc commented Nov 28, 2013

I really dig this.

For boxen new a small suggestion is to also parse a comma separated list of packages: icu4c, ghostscript

You know, for people who don't read instructions.

Also I'd like to see something like boxen new -g fromonesrc/dat_repo to create packages from remote repos.

Owner

fromonesrc commented Nov 28, 2013

boxen project and boxen projects should have the same behavior.

boxen project foo should display some info about foo project.

Owner

ymendel commented Nov 28, 2013

I'm going to set this aside to read more into the implementation later, but my first impressions based entirely on when you @mentioned me (#134 (comment)) are basically "fuck yes". I especially like the "namespaced" commands, like run:noop and service:enable.

I'm tempted to want some slight tweaks, like allowing service and services to both work, just as @fromonesrc mentions project and projects. Also kind of think that boxen services:enable without a specified service should enable all. That's mostly nit-picking than anything else, though.

Looking forward to digging in to seeing how this is laid out. Hoping for good news in the areas of testing, extensibility, &c.

Owner

wfarr commented Nov 28, 2013

Testing is definitely easier now for commands and such.

The branch is still in flux and not near ready for merging yet, but it is coming along nicely.

On Nov 28, 2013, at 12:50 PM, Yossef Mendelssohn notifications@github.com wrote:

Looking forward to digging in to seeing how this is laid out. Hoping for good news in the areas of testing, extensibility, &c.

@dgoodlad dgoodlad referenced this pull request in boxen/puppet-boxen Dec 20, 2013

Merged

add boxen autocomplete #81

wfarr and others added some commits Dec 22, 2013

Commands should not depend on a global Boxen::Config
This forces us to pass the config around explicitly; a bit annoying at
times, but further refactoring should help.
only start servies that were running when doing --restart-servces
Conflicts:
	lib/boxen/runner.rb
	test/boxen_runner_test.rb
Add myself as an author
Conflicts:
	boxen.gemspec
Added functionality for generating dependency graphs
Conflicts:
	lib/boxen/config.rb
	lib/boxen/flags.rb
	lib/boxen/puppeteer.rb
	test/boxen_flags_test.rb
	test/boxen_puppeteer_test.rb
Merge remote-tracking branch 'refs/remotes/origin/master' into next
Conflicts:
	boxen.gemspec
	lib/boxen/config.rb
	lib/boxen/flags.rb
	lib/boxen/puppeteer.rb
	lib/boxen/runner.rb
	test/boxen_flags_test.rb
	test/boxen_puppeteer_test.rb
	test/boxen_runner_test.rb
Fix cli on 1.8.7
I can't wait to :burn: 1.8.7 but too many people are still on OSX 10.8
Owner

dgoodlad commented Jan 15, 2014

So, @wfarr, what else was on your mind for this PR to be legit? I've got a couple of improvements I'll want to make, but they're more internal refactoring than anything.

Owner

wfarr commented Jan 15, 2014

Let's link up on a Hangout tonight or something.

Member

petems commented Jan 16, 2014

Wow, this looks awesome guys 💃

Will this ever land? I'm not sure I want to use boxen without it :P

Owner

wfarr commented Jun 18, 2014

That'd be up to @dgoodlad

On Wed, Jun 18, 2014 at 2:09 AM, André Arko notifications@github.com
wrote:

Will this ever land? I'm not sure I want to use boxen without it :P

Reply to this email directly or view it on GitHub:
#134 (comment)

Owner

dgoodlad commented Jun 18, 2014

Heh, yes it's going to land very soon, just a couple of kinks to work out first!

On 18 Jun 2014, at 7:09 am, André Arko notifications@github.com wrote:

Will this ever land? I'm not sure I want to use boxen without it :P


Reply to this email directly or view it on GitHub.

@wfarr wfarr closed this Jun 3, 2016

@wfarr wfarr deleted the next branch Jun 3, 2016

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