Skip to content

Commit

Permalink
Add documentation for custom commands, accounts restriction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Smith authored and askreet committed Nov 26, 2016
1 parent 2053699 commit aa5d421
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/user-guide/custom-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Custom Commands

One powerful feature of Moonshot is the ability to add custom
project-specific commands. You can hook into many of the features
provided by the `Moonshot::Controller` and `Moonshot::Stack`
interface, and make native calls to AWS using the AWS SDK for Ruby
v2.

To do this, place a file in `moonshot/cli_extensions/my_command.rb`
that extends `Moonshot::Command` (or `Moonshot::SSHCommand`, if you
want to use the Moonshot SSH interface).

## Example

```ruby
# moonshot/cli_extensions/get_elb_address.rb
class GetElbAddress < Moonshot::Command
self.description = 'Display the ELBs external hostname.'
self.usage = 'get-elb-address'

def execute
puts controller.stack.outputs['APIElasticLoadBalancerDNS']
end
end
```

## Account Restrictions

If you have a development- or production-only command you want
restricted to running in appropriately labelled accounts, you can use
the `only_in_account` option. This can be either a single string, or
an array of strings. For example:

```ruby
# moonshot/cli_extensions/drop_database.rb
class DropDatabase < Moonshot::Command
self.description = 'Delete all the data (development only!)'
self.usage = 'drop-database'
self.only_in_account = 'company-dev'

def execute
# ...
end
end
```

If the IAM account alias for the current AWS account does not exactly
match, the user will receive an error:

```
'drop-database' can only be run in the following accounts:
- company-dev
```

0 comments on commit aa5d421

Please sign in to comment.