Browse Source

#6529 - Adjusted the arguments. Fixed documentation

Daniel Sheppard 4 years ago
parent
commit
19bacc9e23

+ 4 - 2
docs/customization/custom-scripts.md

@@ -264,10 +264,12 @@ http://netbox/api/extras/scripts/example.MyReport/ \
 Scripts can be run on the CLI by invoking the management command:
 
 ```
-python3 manage.py runscript [--commit] [--loglevel {debug,info,warning,error,critical}] --script <module>.<script> <data>
+python3 manage.py runscript [--commit] [--loglevel {debug,info,warning,error,critical}] [--data "<data>"] <module>.<script> 
 ```
 
-The required ``--script <module>.<script>`` argument is the report to run where ``<module>`` is the name of the python file in the ``scripts`` directory without the ``.py`` extension and ``<script>`` is the name of the script class in the ``<module>`` to run.
+The required ``<module>.<script>`` argument is the script to run where ``<module>`` is the name of the python file in the ``scripts`` directory without the ``.py`` extension and ``<script>`` is the name of the script class in the ``<module>`` to run.
+
+The optional ``--data "<data>"`` argument is the data to send to the script
 
 The optional ``--loglevel`` argument is the desired logging level to output to the console.
 

+ 8 - 3
netbox/extras/management/commands/runscript.py

@@ -28,10 +28,10 @@ class Command(BaseCommand):
             dest='loglevel',
             default='info',
             choices=['debug', 'info', 'warning', 'error', 'critical'])
-        parser.add_argument('--script', help="Script to run", required=True)
         parser.add_argument('--commit', help="Commit this script to database", action='store_true')
         parser.add_argument('--user', help="User script is running as")
-        parser.add_argument('data', help="Data as a string encapsulated JSON blob")
+        parser.add_argument('--data', help="Data as a string encapsulated JSON blob")
+        parser.add_argument('script', help="Script to run")
 
     def handle(self, *args, **options):
         def _run_script():
@@ -69,7 +69,12 @@ class Command(BaseCommand):
         script = options['script']
         loglevel = options['loglevel']
         commit = options['commit']
-        data = json.loads(options['data']) if options['data'] is not None else None
+        try:
+            data = json.loads(options['data'])
+        except TypeError:
+            data = {}
+
+
 
         module, name = script.split('.', 1)