Skip to content

Commit

Permalink
Use old style namespaces for compatibility, for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
CartBlanche committed Aug 25, 2023
1 parent d505be7 commit 132df6c
Showing 1 changed file with 56 additions and 55 deletions.
111 changes: 56 additions & 55 deletions Meadow.CLI/Commands/Cloud/Collection/ListCollectionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,80 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.Cloud.Collection;

public class ListCollectionCommand
namespace Meadow.CLI.Commands.Cloud.Collection
{
[Command("collection list", Description = "List Meadow Collections")]
public class ListCommand : ICommand
public class ListCollectionCommand
{
private readonly ILogger<LogoutCommand> _logger;
UserService _userService;
private CollectionService _collectionService;
IConfiguration _config;

public ListCommand(ILoggerFactory loggerFactory, UserService userService, CollectionService collectionService,
IConfiguration config)
[Command("collection list", Description = "List Meadow Collections")]
public class ListCommand : ICommand
{
_logger = loggerFactory.CreateLogger<LogoutCommand>();
_userService = userService;
_collectionService = collectionService;
_config = config;
}
private readonly ILogger<LogoutCommand> _logger;
UserService _userService;
private CollectionService _collectionService;
IConfiguration _config;

[CommandOption("orgId", 'o', Description = "Organization Id", IsRequired = false)]
public string OrgId { get; set; }
[CommandOption("host", Description = "Optionally set a host (default is https://www.meadowcloud.co)", IsRequired = false)]
public string Host { get; set; }

public async ValueTask ExecuteAsync(IConsole console)
{
var cancellationToken = console.RegisterCancellationHandler();
public ListCommand(ILoggerFactory loggerFactory, UserService userService, CollectionService collectionService,
IConfiguration config)
{
_logger = loggerFactory.CreateLogger<LogoutCommand>();
_userService = userService;
_collectionService = collectionService;
_config = config;
}

await Task.Yield();
[CommandOption("orgId", 'o', Description = "Organization Id", IsRequired = false)]
public string OrgId { get; set; }
[CommandOption("host", Description = "Optionally set a host (default is https://www.meadowcloud.co)", IsRequired = false)]
public string Host { get; set; }

try
public async ValueTask ExecuteAsync(IConsole console)
{
var userOrgs = await _userService.GetUserOrgs(Host, cancellationToken).ConfigureAwait(false);
if (!userOrgs.Any())
var cancellationToken = console.RegisterCancellationHandler();

await Task.Yield();

try
{
_logger.LogInformation($"Please visit {_config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME]} to register your account.");
return;
var userOrgs = await _userService.GetUserOrgs(Host, cancellationToken).ConfigureAwait(false);
if (!userOrgs.Any())
{
_logger.LogInformation($"Please visit {_config[Constants.MEADOW_CLOUD_HOST_CONFIG_NAME]} to register your account.");
return;
}
else if (userOrgs.Count() > 1 && string.IsNullOrEmpty(OrgId))
{
_logger.LogInformation($"Please specify the orgId.");
return;
}
else if (userOrgs.Count() == 1 && string.IsNullOrEmpty(OrgId))
{
OrgId = userOrgs.First().Id;
}

if (!userOrgs.Select(x => x.Id).Contains(OrgId))
{
_logger.LogInformation($"Invalid orgId: {OrgId}");
return;
}
}
else if (userOrgs.Count() > 1 && string.IsNullOrEmpty(OrgId))
catch (MeadowCloudAuthException)
{
_logger.LogInformation($"Please specify the orgId.");
_logger.LogInformation($"You must be signed in to execute this command.");
return;
}
else if (userOrgs.Count() == 1 && string.IsNullOrEmpty(OrgId))

var collections = await _collectionService.GetOrgCollections(OrgId, Host, cancellationToken);

if (collections == null || collections.Count() == 0)
{
OrgId = userOrgs.First().Id;
_logger.LogInformation("No collections found.");
}

if (!userOrgs.Select(x => x.Id).Contains(OrgId))
foreach (var collection in collections)
{
_logger.LogInformation($"Invalid orgId: {OrgId}");
return;
_logger.LogInformation($"{collection.Id} | {collection.Name}");
}
}
catch (MeadowCloudAuthException)
{
_logger.LogInformation($"You must be signed in to execute this command.");
return;
}

var collections = await _collectionService.GetOrgCollections(OrgId, Host, cancellationToken);

if (collections == null || collections.Count() == 0)
{
_logger.LogInformation("No collections found.");
}

foreach (var collection in collections)
{
_logger.LogInformation($"{collection.Id} | {collection.Name}");
}
}
}
}

0 comments on commit 132df6c

Please sign in to comment.