Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

CLI-next #134

Open
wants to merge 83 commits into from

9 participants

@wfarr
Owner

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
@@ -1,8 +1,12 @@
# -*- encoding: utf-8 -*-
+lib = File.expand_path("./lib", File.dirname(__FILE__))
+$:.unshift lib
+require "boxen/version"
+
@jbarnette Owner
load "lib/boxen/version.rb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/boxen/commands/command.rb
@@ -0,0 +1,41 @@
+require "boxen/commands"
+
+module Boxen
+ module Commands
+ class Command
@jbarnette Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/boxen/commands/command.rb
@@ -0,0 +1,41 @@
+require "boxen/commands"
+
+module Boxen
+ module Commands
+ class Command
+
+ class << self
@jbarnette Owner

I always prefer self. for grepability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/boxen/commands/command.rb
@@ -0,0 +1,41 @@
+require "boxen/commands"
+
+module Boxen
+ module Commands
+ class Command
+
+ class << self
+ def preflight(*klasses)
@jbarnette Owner

All this goes away if there's a:

def preflights
  @preflights ||= []
end

Same for postflights.

@jbarnette Owner
def preflight(*klasses)
  preflights.replace preflights | klasses.flatten
end

...or however you feel like dealing with dups and nesting. :smile:

@wfarr Owner
wfarr added a note

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>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/boxen/commands/command.rb
((22 lines not shown))
+ end
+ end
+
+ def initialize(*args)
+ @args = args
+ end
+
+ def invoke
+ if self.class.preflight.all? { |p| p = p.new; p.run unless p.ok? }
+ self.run
+ self.class.postflight.each { |p| p = p.new; p.run unless p.ok? }
+ end
+ end
+
+ def run
+ raise NotImplementedError
@jbarnette Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/boxen/commands/command.rb
((14 lines not shown))
+ end
+
+ def postflight(*klasses)
+ if defined?(@postflight)
+ @postflight += klasses
+ else
+ @postflight = klasses
+ end
+ end
+ end
+
+ def initialize(*args)
+ @args = args
+ end
+
+ def invoke
@jbarnette Owner

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

@wfarr Owner
wfarr added a note

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

invoke is only used internally.

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

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.
@wfarr
Owner

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.

@wfarr
Owner

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

@jbarnette
Owner

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

@wfarr
Owner

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.

@jbarnette
Owner

:boom::camel:

@wfarr
Owner

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.

@fromonesrc
Owner

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.

@fromonesrc
Owner

boxen project and boxen projects should have the same behavior.

boxen project foo should display some info about foo project.

@ymendel
Owner

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.

@wfarr
Owner
@dgoodlad dgoodlad referenced this pull request in boxen/puppet-boxen
Merged

add boxen autocomplete #81

grosser and others added some commits
@grosser grosser only start servies that were running when doing --restart-servces
Conflicts:
	lib/boxen/runner.rb
	test/boxen_runner_test.rb
1e29131
@dgoodlad dgoodlad Add myself as an author
Conflicts:
	boxen.gemspec
1ebb422
@dieterdemeyer dieterdemeyer 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
71af6af
@dgoodlad dgoodlad 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
d3dadb8
@dgoodlad dgoodlad FUUUUUU 1.8.7 rubygems a61a32f
@dgoodlad dgoodlad 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
57744b6
@dgoodlad
Owner

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.

@wfarr
Owner

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

@petems

Wow, this looks awesome guys :dancer:

wfarr and others added some commits
@wfarr wfarr raise a real error if the command isn't registered or the name is nil 4099565
@wfarr wfarr Properly display nils 1d6c7d4
@wfarr wfarr General hacks to get things working-ish 1717069
@wfarr wfarr tests 584d5ae
@wfarr wfarr don't rely on config to perform debug check d9a7850
@wfarr wfarr fix offline check for run 06fe5ac
@wfarr wfarr BOOM IT WORKS (if you have a special, patched facter b5a0a83
@wfarr wfarr add logger and updater 3d07188
@wfarr wfarr Begin spiking out a friendly CLI wrapper 232db95
@wfarr wfarr bugs and such 62d6b41
@wfarr wfarr Make sure we require the system gems we need for ya know things 3858c9b
@wfarr wfarr Add a boxen preflight command fed37da
@wfarr wfarr Don't hardcode offline a73feed
@wfarr wfarr use a longer timeout 8750d00
@dgoodlad dgoodlad Enable debug output in pre-/post-flight checks 2c475e0
@dgoodlad dgoodlad Make auto-update work, and re-run if we updated a66faf1
@dgoodlad dgoodlad Make `boxen --help` run as `boxen help` 83112bf
@dgoodlad dgoodlad Add explicit support for command aliases 5e7def3
@dgoodlad dgoodlad Use aliases rather than double-registered commands 83e63d2
@dgoodlad dgoodlad Fix the debug flag
@wfarr was this really meant to be the inverse of @debug, or was that
a temporary testing thing?
604e56c
@dgoodlad dgoodlad Only fetch if we're going to update c8db8b2
@dgoodlad dgoodlad Merge branch 'master' into next
Conflicts:
	boxen.gemspec
	lib/boxen/hook.rb
0dc2498
@dgoodlad dgoodlad Add `boxen` binary 7b69106
@dgoodlad dgoodlad Print deprecation warnings for old-style hooks c20f0f4
@dgoodlad dgoodlad Make the old Hook::GithubIssue a postflight instead
This brings in some legacy stuff, like required_environment_variables,
to be refactored.
586554e
@indirect

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

@wfarr
Owner
@dgoodlad
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2013
  1. @wfarr
  2. @wfarr
  3. @wfarr
  4. @wfarr

    Add help command for nwo

    wfarr authored
  5. @wfarr
  6. @wfarr
  7. @wfarr
  8. @wfarr

    self dot for @jbarnette

    wfarr authored
  9. @wfarr
  10. @wfarr

    load over load path

    wfarr authored
Commits on Nov 27, 2013
  1. @wfarr

    ell oh ell

    wfarr authored
  2. @wfarr

    whatevs

    wfarr authored
  3. @wfarr
  4. @wfarr
  5. @wfarr

    pull in run and noop commands

    wfarr authored
  6. @wfarr

    Rip out Puppeteer

    wfarr authored
  7. @wfarr
  8. @wfarr

    reorganize test dir a bit

    wfarr authored
  9. @wfarr
  10. @wfarr

    Fix tests for detailed help

    wfarr authored
  11. @wfarr
  12. @wfarr

    Add service command

    wfarr authored
    Remove old Runner code for this and their tests as well
  13. @wfarr
  14. @wfarr

    whoops

    wfarr authored
  15. @wfarr

    typo

    wfarr authored
Commits on Dec 4, 2013
  1. @wfarr
  2. @wfarr

    Alias services to service

    wfarr authored
  3. @wfarr
  4. @wfarr
  5. @wfarr

    Get rid of attr_reader

    wfarr authored
  6. @wfarr

    skip token test

    wfarr authored
Commits on Dec 18, 2013
  1. @wfarr
Commits on Dec 22, 2013
  1. @wfarr

    Upgrade minitest dependency

    wfarr authored
  2. @wfarr
  3. @wfarr

    fix hook test

    wfarr authored
  4. @wfarr
  5. @wfarr

    Loads more cleanup

    wfarr authored
Commits on Jan 9, 2014
  1. @dgoodlad

    Commands should not depend on a global Boxen::Config

    dgoodlad authored
    This forces us to pass the config around explicitly; a bit annoying at
    times, but further refactoring should help.
Commits on Jan 12, 2014
  1. @dgoodlad

    Add the `project` command

    dgoodlad authored
Commits on Jan 13, 2014
  1. @dgoodlad
  2. @dgoodlad
Commits on Jan 15, 2014
  1. @grosser @dgoodlad

    only start servies that were running when doing --restart-servces

    grosser authored dgoodlad committed
    Conflicts:
    	lib/boxen/runner.rb
    	test/boxen_runner_test.rb
  2. @dgoodlad

    Add myself as an author

    dgoodlad authored
    Conflicts:
    	boxen.gemspec
  3. @dieterdemeyer @dgoodlad

    Added functionality for generating dependency graphs

    dieterdemeyer authored dgoodlad committed
    Conflicts:
    	lib/boxen/config.rb
    	lib/boxen/flags.rb
    	lib/boxen/puppeteer.rb
    	test/boxen_flags_test.rb
    	test/boxen_puppeteer_test.rb
  4. @dgoodlad

    Merge remote-tracking branch 'refs/remotes/origin/master' into next

    dgoodlad authored
    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
  5. @dgoodlad

    FUUUUUU 1.8.7 rubygems

    dgoodlad authored
  6. @dgoodlad

    Fix cli on 1.8.7

    dgoodlad authored
    I can't wait to :burn: 1.8.7 but too many people are still on OSX 10.8
Commits on Mar 7, 2014
  1. @wfarr
  2. @wfarr

    Properly display nils

    wfarr authored
  3. @wfarr
  4. @wfarr

    tests

    wfarr authored
  5. @wfarr
  6. @wfarr

    fix offline check for run

    wfarr authored
  7. @wfarr
  8. @wfarr

    add logger and updater

    wfarr authored
Commits on Mar 8, 2014
  1. @wfarr
  2. @wfarr

    bugs and such

    wfarr authored
Commits on Mar 10, 2014
  1. @wfarr
  2. @wfarr

    Add a boxen preflight command

    wfarr authored
  3. @wfarr

    Don't hardcode offline

    wfarr authored
  4. @wfarr

    use a longer timeout

    wfarr authored
Commits on Mar 20, 2014
  1. @dgoodlad
  2. @dgoodlad
  3. @dgoodlad
  4. @dgoodlad
  5. @dgoodlad
  6. @dgoodlad

    Fix the debug flag

    dgoodlad authored
    @wfarr was this really meant to be the inverse of @debug, or was that
    a temporary testing thing?
  7. @dgoodlad
Commits on May 6, 2014
  1. @dgoodlad

    Merge branch 'master' into next

    dgoodlad authored
    Conflicts:
    	boxen.gemspec
    	lib/boxen/hook.rb
Commits on May 7, 2014
  1. @dgoodlad

    Add `boxen` binary

    dgoodlad authored
  2. @dgoodlad
  3. @dgoodlad

    Make the old Hook::GithubIssue a postflight instead

    dgoodlad authored
    This brings in some legacy stuff, like required_environment_variables,
    to be refactored.
Commits on Jul 30, 2014
  1. @dgoodlad

    Typo

    dgoodlad authored
  2. @dgoodlad
  3. @dgoodlad
  4. @dgoodlad

    Fix postflight active test

    dgoodlad authored
  5. @dgoodlad
  6. @dgoodlad

    Don't skip the token test

    dgoodlad authored
  7. @dgoodlad
  8. @dgoodlad
  9. @dgoodlad
Commits on Jul 31, 2014
  1. @dgoodlad
  2. @dgoodlad

    3.0.0.beta1

    dgoodlad authored
Something went wrong with that request. Please try again.