using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon.Common.DotNetCli.Tools;
using Amazon.Common.DotNetCli.Tools.Options;
using Amazon.Lambda.Model;
using ThirdParty.Json.LitJson;
namespace Amazon.Lambda.Tools.Commands
{
///
/// List all the functions currently deployed to Lambda
///
public class ListFunctionCommand : LambdaBaseCommand
{
public const string COMMAND_NAME = "list-functions";
public const string COMMAND_DESCRIPTION = "Command to list all your Lambda functions";
public static readonly IList ListCommandOptions = BuildLineOptions(new List
{
});
public ListFunctionCommand(IToolLogger logger, string workingDirectory, string[] args)
: base(logger, workingDirectory, ListCommandOptions, args)
{
}
///
/// Parse the CommandOptions into the Properties on the command.
///
///
protected override void ParseCommandArguments(CommandOptions values)
{
base.ParseCommandArguments(values);
}
protected override async Task PerformActionAsync()
{
ListFunctionsRequest request = new ListFunctionsRequest();
ListFunctionsResponse response = null;
do
{
if (response != null)
request.Marker = response.NextMarker;
try
{
response = await this.LambdaClient.ListFunctionsAsync(request);
}
catch (Exception e)
{
throw new LambdaToolsException("Error listing Lambda functions: " + e.Message, LambdaToolsException.LambdaErrorCode.LambdaListFunctions, e);
}
foreach (var function in response.Functions)
{
var extraInfo = function.PackageType == Lambda.PackageType.Zip ? "Runtime: " + function.Runtime.Value : "Package Type: " + function.PackageType.Value;
this.Logger.WriteLine((function.FunctionName.PadRight(40) + " (" + extraInfo + ")").PadRight(10) + "\t" + function.Description);
}
} while (!string.IsNullOrEmpty(response.NextMarker));
return true;
}
protected override void SaveConfigFile(JsonData data)
{
}
}
}