Skip to content

Commit

Permalink
feat(project): add new project command to facilitate setting build ty…
Browse files Browse the repository at this point in the history
…pe variations of the app id, and version (resolves #157)
  • Loading branch information
marchbold committed Feb 24, 2023
1 parent b5c89d4 commit 3da01bb
Show file tree
Hide file tree
Showing 10 changed files with 647 additions and 99 deletions.
11 changes: 8 additions & 3 deletions client/src/com/apm/client/APM.as
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ package com.apm.client
import com.apm.client.commands.project.GenerateAppDescriptorCommand;
import com.apm.client.commands.project.GenerateConfigCommand;
import com.apm.client.commands.project.InitCommand;
import com.apm.client.commands.project.ProjectCommand;
import com.apm.client.commands.project.ProjectConfigCommand;
import com.apm.client.config.RunConfig;
import com.apm.client.events.CommandEvent;
Expand Down Expand Up @@ -111,6 +112,7 @@ package com.apm.client

// project commands
addCommand( InitCommand.NAME, InitCommand );
addCommand( ProjectCommand.NAME, ProjectCommand );
addCommand( ProjectConfigCommand.NAME, ProjectConfigCommand );
addCommand( GenerateAppDescriptorCommand.NAME, GenerateAppDescriptorCommand );
addCommand( GenerateConfigCommand.NAME, GenerateConfigCommand );
Expand Down Expand Up @@ -250,10 +252,13 @@ package com.apm.client
{
// Check for command
var CommandClass:Class = getCommand( arg );
if (CommandClass == null && i + 1 < arguments.length)
if (i + 1 < arguments.length)
{
CommandClass = getCommand( arg + "/" + arguments[ i + 1 ] )
if (CommandClass != null) i++;
var SubCommandClass:Class = getCommand( arg + "/" + arguments[ i + 1 ] )
if (SubCommandClass != null) {
CommandClass = SubCommandClass;
i++;
}
}

if (CommandClass != null)
Expand Down
71 changes: 35 additions & 36 deletions client/src/com/apm/client/commands/packages/ListCommand.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,94 +17,93 @@ package com.apm.client.commands.packages
import com.apm.client.commands.Command;
import com.apm.client.events.CommandEvent;
import com.apm.data.project.ProjectDefinition;

import flash.events.EventDispatcher;



public class ListCommand extends EventDispatcher implements Command
{

////////////////////////////////////////////////////////
// CONSTANTS
//

private static const TAG:String = "ListCommand";


public static const NAME:String = "list";


////////////////////////////////////////////////////////
// VARIABLES
//

private var _parameters:Array;

////////////////////////////////////////////////////////
// FUNCTIONALITY
//

public function ListCommand()
{
super();
}


public function setParameters( parameters:Array ):void
{
_parameters = parameters;
}


public function get name():String
{
return NAME;
}


public function get category():String
{
return "";
}


public function get requiresNetwork():Boolean
{
return false;
}


public function get requiresProject():Boolean
{
return true;
}


public function get description():String
{
return "lists dependencies currently added to your project";
}


public function get usage():String
{
return description + "\n" +
"\n" +
"apm list list all the dependencies in your project\n"
}


public function execute():void
{
var project:ProjectDefinition = APM.config.projectDefinition;
if (project == null)
{
APM.io.writeLine( "ERROR: project definition not found" );
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ));
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ) );
return;
}
APM.io.writeLine( project.applicationFilename + "@" + project.version + " " + APM.config.workingDirectory + "" );

APM.io.writeLine( project.getApplicationId( APM.config.buildType ) + "@" + project.getVersion( APM.config.buildType ) + " " + APM.config.workingDirectory + "" );
if (project.dependencies.length == 0)
{
APM.io.writeLine( "└── (empty)" );
Expand All @@ -115,13 +114,13 @@ package com.apm.client.commands.packages
{
APM.io.writeLine(
(i == project.dependencies.length - 1 ? "└──" : "├──") +
project.dependencies[ i ].toString() );
project.dependencies[i].toString() );
}
}
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_OK ));
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_OK ) );

}

}

}
185 changes: 185 additions & 0 deletions client/src/com/apm/client/commands/project/ProjectCommand.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/**
* __ __ __
* ____/ /_ ____/ /______ _ ___ / /_
* / __ / / ___/ __/ ___/ / __ `/ __/
* / /_/ / (__ ) / / / / / /_/ / /
* \__,_/_/____/_/ /_/ /_/\__, /_/
* / /
* \/
* http://distriqt.com
*
* @author Michael (https://github.com/marchbold)
* @created 24/2/2023
*/
package com.apm.client.commands.project
{
import com.apm.client.APM;
import com.apm.client.commands.Command;
import com.apm.client.commands.project.processes.ProjectGetProcess;
import com.apm.client.commands.project.processes.ProjectSetProcess;
import com.apm.client.events.CommandEvent;
import com.apm.client.logging.Log;
import com.apm.client.processes.ProcessQueue;

import flash.events.EventDispatcher;

public class ProjectCommand extends EventDispatcher implements Command
{

////////////////////////////////////////////////////////
// CONSTANTS
//

private static const TAG:String = "ProjectCommand";

public static const NAME:String = "project";


////////////////////////////////////////////////////////
// VARIABLES
//

private var _parameters:Array;


////////////////////////////////////////////////////////
// FUNCTIONALITY
//

public function ProjectCommand()
{
super();
_parameters = [];
}


public function setParameters( parameters:Array ):void
{
_parameters = parameters;
}


public function get name():String
{
return NAME;
}


public function get category():String
{
return "";
}


public function get requiresNetwork():Boolean
{
return false;
}


public function get requiresProject():Boolean
{
return true;
}


public function get description():String
{
return "controls the project parameters saved in the project definition";
}


public function get usage():String
{
return description + "\n" +
"\n" +
"apm project Prints all project parameters \n" +
"apm project set <param> <value> Sets a <param> project parameter to the specified <value> \n" +
"apm project set <param> Asks for input to set the value for the <param> project parameter \n" +
"apm project get <param> Prints the project parameter value for the <param> parameter \n"
;
}


public function execute():void
{
Log.d( TAG, "execute(): [" + (_parameters.length > 0 ? _parameters.join( " " ) : " ") + "]\n" );
try
{
var queue:ProcessQueue = new ProcessQueue();

if (_parameters.length > 0)
{
var subCommand:String = _parameters[0];
switch (subCommand)
{
case "set":
{
if (_parameters.length < 2)
{
dispatchEvent( new CommandEvent( CommandEvent.PRINT_USAGE, name ) );
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ) );
return;
}

queue.addProcess( new ProjectSetProcess(
_parameters.length < 2 ? null : _parameters[1],
_parameters.length < 3 ? null : _parameters.slice( 2 ).join( " " )
) );

break;
}

case "get":
{
if (_parameters.length < 2)
{
queue.addProcess( new ProjectGetProcess( null ) );
}
else
{
queue.addProcess( new ProjectGetProcess( _parameters[1] ) );
}
break;
}

default:
{
dispatchEvent( new CommandEvent( CommandEvent.PRINT_USAGE, name ) );
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ) );
return;
}
}
}
else
{
// print all config
queue.addProcess( new ProjectGetProcess( null ) );
}


queue.start(
function ():void
{
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_OK ) );
},
function ( error:String ):void
{
APM.io.writeError( NAME, error );
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ) );
}
);

}
catch (e:Error)
{
APM.io.error( e );
dispatchEvent( new CommandEvent( CommandEvent.COMPLETE, APM.CODE_ERROR ) );
}
}


}


}
Loading

0 comments on commit 3da01bb

Please sign in to comment.