#! /usr/bin/env python
from __future__ import print_function

import datetime
import os
import sys
import json
import uuid

if len(sys.argv) > 1:
    invocation = sys.argv[1]
else:
    sys.stderr.write("Usage: python "+sys.argv[0]+" 'command-invocation'"+'\n')
    sys.exit(1)

def get_year():
    now = datetime.datetime.now()
    return now.year

def get_username():
    try:
        # POSIX only
        import pwd
        gecos_field =  pwd.getpwuid(os.getuid()).pw_gecos
        full_name = gecos_field.split(',')[0]
        return full_name
    except ImportError:
        import getpass
        return getpass.getuser()

new_uuid = str(uuid.uuid4())

oyster = \
{
    "component-commands": [
        "<FIXME>"
    ],
    "copying": {
        "authors": [
            get_username()
        ],
        "license-name": "MIT (Expat) License",
        "license-url": "http://opensource.org/licenses/MIT",
        "year": get_year()
    },
    "description": {
        "verbose-description": "<FIXME>"
    },
    "invocations": [
        {
            "invocation-string": invocation
        }
    ],
    "uuid": new_uuid
}

root = sys.path[0]
new_filename = new_uuid + '.json'
new_filepath = os.path.join(root, 'cmdoysters', new_filename)
with open(new_filepath, 'w') as new_file:
    json.dump(oyster, new_file, indent=4, separators=(',', ': '), sort_keys=True)
    print('Created new CmdOyster:\n{}'.format(new_filepath))

@@ -121,162 +121,8 @@
 id%0A%0A
-if len(sys.argv) %3E 1:%0A    invocation = sys.argv%5B1%5D%0Aelse:%0A    sys.stderr.write(%22Usage: python %22+sys.argv%5B0%5D+%22 'command-invocation'%22+'%5Cn')%0A    sys.exit(1)%0A%0A
 def 
@@ -467,16 +467,170 @@
 user()%0A%0A
+if len(sys.argv) %3E 1:%0A    invocation = sys.argv%5B1%5D%0Aelse:%0A    sys.stderr.write(%22Usage: python %22+sys.argv%5B0%5D+%22 'command-invocation'%22+'%5Cn')%0A    sys.exit(1)%0A%0A
 new_uuid

Move this below the function definitions.