Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

Command Line Utility Output

Open marchbold opened this issue 5 years ago • 37 comments

Feature

Recently we have been discussing the development of an AIR package manager to simplify handling dependencies on AIR applications.

To aid this development it would be helpful to be able to develop command line utilities in AS3. These utilities would not have any window or ui, simply be commands run on the command line.

Required Changes

  1. Removing the UI window requirements

We can currently hide the window but removing it altogether would be preferable.

  1. Access to stdin/stdout functionality

Currently input is limited to the invoke event to get arguments and output to trace statements. We would need to be able to:

  • capture keyboard input from the terminal
  • write / update output to the terminal
  1. Package into a command line utility (could be an alternative of adl?)

Example

This is a simple example of what is currently possible.

In this example, we simply use trace to output the command line arguments.

package
{
	import flash.desktop.NativeApplication;
	import flash.display.Sprite;
	import flash.events.InvokeEvent;
	
	public class Main extends Sprite
	{
		public function Main()
		{
			trace( "start..." );
			NativeApplication.nativeApplication.addEventListener( InvokeEvent.INVOKE, invokeHandler );
		}
		
		private function invokeHandler( event:InvokeEvent ):void
		{
			trace( event.arguments );
			NativeApplication.nativeApplication.exit( 0 );
		}
		
	}
}

To invoke this on the command line we would compile the swf and then use a simple app xml:

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/33.1">
    <id>Main</id>
    <filename>Main</filename>
    <name>Main</name>
    <versionNumber>0.0.0</versionNumber>
    <initialWindow>
        <content>Main.swf</content>
        <visible>false</visible>
    </initialWindow>
</application>

We can create a small script to invoke this using adl and passing arguments, eg if we have the following in a Main.sh script (with Main.swf and Main-app.xml in an out directory):

#!/bin/bash
adl -profile extendedDesktop out/Main-app.xml out -- $@

Then we can call it using

./Main.sh -s some_parameter 

This would result in the following output:

start...
-s some_parameter

marchbold avatar Sep 14 '20 04:09 marchbold