softlayer/softlayer-api-python-client — pull request #39 by sudorandom (2013-02-14 16:44:58+00:00)
Title: Adds FormattedItem class

This changes how the CLIRunnables define formatted values in a way that will perserve the raw value. The signature is this: FormattedItem(raw, formatted). Along with this is a helper that converts raw megabyte values to gigabytes.
Using mb_to_gb, a helper that creates a FormattedItem. This will show '1024' for 'raw' and 1G for the table formatter.''

```python
from SoftLayer.CLI import CLIRunnable, mb_to_gb

class CLIRunnable(object):
action = 'example_action'

@staticmethod
def execute(client, args):
return mb_to_gb(1024)
```

Using FormattedItem Directly. This will show '48' for raw and '2 days' for the table formatter.
```python
from SoftLayer.CLI import CLIRunnable, FormattedItem

class CLIRunnable(object):
action = 'example_action'

@staticmethod
def execute(client, args):
return FormattedItem(48, '2 days')
```

This is an example of creating a helper. This will append 'is cool' to the string using the table formatter. All formatters should live in SoftLayer/CLI/helpers.py
```python
def is_cool(string):
return FormattedItem(string, string + " is cool")
```