Browse Source

Added Add module command

pull/1103/head
Halil ibrahim Kalkan 8 years ago
parent
commit
ccc89803a1
  1. 55
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddCommand.cs
  2. 27
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddCommandHelper.cs
  3. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CommandSelector.cs
  4. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs
  5. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewProjectCommand.cs
  6. 26
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/AddModuleArgs.cs
  7. 137
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/ModuleAdder.cs
  8. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/ProjectModuleAdder.cs
  9. 13
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/SolutionModuleAdder.cs
  10. 4
      framework/src/Volo.Abp.Core/Volo/Abp/Modularity/IAbpModule.cs

55
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddCommand.cs

@ -0,0 +1,55 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System.Threading.Tasks;
using Volo.Abp.Cli.Args;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ProjectModification;
namespace Volo.Abp.Cli.Commands
{
public class AddCommand : IConsoleCommand, ITransientDependency
{
public ILogger<AddCommand> Logger { get; set; }
protected ModuleAdder ModuleAdder { get; }
public AddCommand(ModuleAdder moduleAdder)
{
ModuleAdder = moduleAdder;
Logger = NullLogger<AddCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{
if (commandLineArgs.Target == null)
{
Logger.LogWarning("Module name is missing.");
AddCommandHelper.WriteUsage(Logger);
return;
}
await ModuleAdder.AddModuleAsync(
new AddModuleArgs(
commandLineArgs.Target,
commandLineArgs.Options.GetOrNull(Options.Solution.Short, Options.Solution.Long),
commandLineArgs.Options.GetOrNull(Options.Project.Short, Options.Project.Long)
)
);
}
public static class Options
{
public static class Solution
{
public const string Short = "s";
public const string Long = "solution";
}
public static class Project
{
public const string Short = "p";
public const string Long = "project";
}
}
}
}

27
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddCommandHelper.cs

@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
namespace Volo.Abp.Cli.Commands
{
public static class AddCommandHelper
{
public static void WriteUsage(ILogger logger)
{
logger.LogWarning("");
logger.LogWarning("'add' command is used to add a module to a solution or to a project.");
logger.LogWarning("Use in a solution folder to add a multi-package module to a solution.");
logger.LogWarning("Use in a project folder to add a single-package module to a project.");
logger.LogWarning("");
logger.LogWarning("Usage:");
logger.LogWarning(" abp add <module-name> [-s|--solution] [-p|--project]");
logger.LogWarning("");
logger.LogWarning("Options:");
logger.LogWarning(" -s|--solution <solution-file> Specify solution file explicitly.");
logger.LogWarning(" -p|--project <project-file> Specify project file explicitly.");
logger.LogWarning("");
logger.LogWarning("Examples:");
logger.LogWarning(" abp add Volo.Abp.TenantManagement Adds tenant management module packages to the solution.");
logger.LogWarning(" abp add Volo.Abp.FluentValidation Adds a single module package to the project.");
logger.LogWarning("");
}
}
}

10
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CommandSelector.cs

@ -9,14 +9,18 @@ namespace Volo.Abp.Cli.Commands
public Type Select(CommandLineArgs commandLineArgs)
{
//TODO: Create options to define commands
//TODO: Get from dependency injection instead of new?
if (commandLineArgs.Command == "new")
{
return typeof(NewProjectCommand);
return typeof(NewCommand);
}
return typeof(MainHelpCommand);
if (commandLineArgs.Command == "add")
{
return typeof(AddCommand);
}
return typeof(HelpCommand);
}
}
}

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/MainHelpCommand.cs → framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/HelpCommand.cs

@ -5,7 +5,7 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.Commands
{
public class MainHelpCommand : IConsoleCommand, ITransientDependency
public class HelpCommand : IConsoleCommand, ITransientDependency
{
public Task ExecuteAsync(CommandLineArgs commandLineArgs)
{

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewProjectCommand.cs

@ -10,17 +10,17 @@ using Volo.Abp.ProjectBuilding.Building;
namespace Volo.Abp.Cli.Commands
{
public class NewProjectCommand : IConsoleCommand, ITransientDependency
public class NewCommand : IConsoleCommand, ITransientDependency
{
public ILogger<NewProjectCommand> Logger { get; set; }
public ILogger<NewCommand> Logger { get; set; }
protected ProjectBuilder ProjectBuilder { get; }
public NewProjectCommand(ProjectBuilder projectBuilder)
public NewCommand(ProjectBuilder projectBuilder)
{
ProjectBuilder = projectBuilder;
Logger = NullLogger<NewProjectCommand>.Instance;
Logger = NullLogger<NewCommand>.Instance;
}
public async Task ExecuteAsync(CommandLineArgs commandLineArgs)

26
framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/AddModuleArgs.cs

@ -0,0 +1,26 @@
using JetBrains.Annotations;
namespace Volo.Abp.ProjectModification
{
public class AddModuleArgs
{
[NotNull]
public string ModuleName { get; set; }
[CanBeNull]
public string SolutionFile { get; set; }
[CanBeNull]
public string ProjectFile { get; set; }
public AddModuleArgs(
[NotNull] string moduleName,
[CanBeNull] string solutionFile = null,
[CanBeNull] string projectFile = null)
{
ModuleName = Check.NotNullOrWhiteSpace(moduleName, nameof(moduleName));
SolutionFile = solutionFile;
ProjectFile = projectFile;
}
}
}

137
framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/ModuleAdder.cs

@ -0,0 +1,137 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Cli.Commands;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.ProjectModification
{
public class ModuleAdder : ITransientDependency
{
public ILogger<ModuleAdder> Logger { get; set; }
protected ProjectModuleAdder ProjectModuleAdder { get; }
protected SolutionModuleAdder SolutionModuleAdder { get; }
public ModuleAdder(ProjectModuleAdder projectModuleAdder, SolutionModuleAdder solutionModuleAdder)
{
ProjectModuleAdder = projectModuleAdder;
SolutionModuleAdder = solutionModuleAdder;
Logger = NullLogger<ModuleAdder>.Instance;
}
public async Task AddModuleAsync(AddModuleArgs args)
{
ValidateArgs(args);
NormalizeArgs(args);
if (args.ProjectFile.IsNullOrEmpty() && args.SolutionFile.IsNullOrEmpty())
{
if (!TryToFillProjectOrSolutionName(args))
{
Logger.LogWarning("Could not find any project (.csproj) or solution (.sln) file in the current directory!");
AddCommandHelper.WriteUsage(Logger);
return;
}
}
if (!args.ProjectFile.IsNullOrEmpty())
{
await ProjectModuleAdder.AddAsync(args.ProjectFile, args.ModuleName);
}
if (!args.SolutionFile.IsNullOrEmpty())
{
await SolutionModuleAdder.AddAsync(args.SolutionFile, args.ModuleName);
}
}
private bool TryToFillProjectOrSolutionName(AddModuleArgs args)
{
var projectFiles = FindFiles(Directory.GetCurrentDirectory(), ".csproj");
if (projectFiles.Count == 1)
{
args.ProjectFile = projectFiles.First();
return true;
}
if (projectFiles.Count > 1)
{
Logger.LogWarning(
"There are multiple project (.csproj) files in the current directory. Please specify one of the files below:");
foreach (var projectFile in projectFiles)
{
Logger.LogWarning("* " + projectFile);
}
Logger.LogWarning("Example:");
Logger.LogWarning($"abp add {args.ModuleName} -p {projectFiles[0]}");
return false;
}
var solutionFiles = FindFiles(Directory.GetCurrentDirectory(), ".sln");
if (solutionFiles.Count == 1)
{
args.SolutionFile = solutionFiles.First();
return true;
}
if (solutionFiles.Count > 1)
{
Logger.LogWarning(
"There are multiple solution (.sln) files in the current directory. Please specify one of the files below:");
foreach (var solutionFile in solutionFiles)
{
Logger.LogWarning("* " + solutionFile);
}
Logger.LogWarning("Example:");
Logger.LogWarning($"abp add {args.ModuleName} -s {solutionFiles[0]}");
}
return false;
}
private void ValidateArgs(AddModuleArgs args)
{
if (!args.ProjectFile.IsNullOrEmpty() &&
!args.SolutionFile.IsNullOrEmpty())
{
throw new ArgumentException("Can not specify a solution name and project name together.");
}
}
private void NormalizeArgs(AddModuleArgs args)
{
args.ProjectFile = NormalizePath(args.ProjectFile);
args.SolutionFile = NormalizePath(args.SolutionFile);
}
private static string NormalizePath([CanBeNull] string path)
{
if (string.IsNullOrEmpty(path))
{
return path;
}
if (Path.IsPathRooted(path))
{
return path;
}
return Path.Combine(Directory.GetCurrentDirectory(), path);
}
private List<string> FindFiles(string directory, string fileExtension)
{
throw new NotImplementedException();
}
}
}

13
framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/ProjectModuleAdder.cs

@ -0,0 +1,13 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.ProjectModification
{
public class ProjectModuleAdder : ITransientDependency
{
public async Task AddAsync(string projectFile, string moduleName)
{
}
}
}

13
framework/src/Volo.Abp.Cli.Core/Volo/Abp/ProjectModification/SolutionModuleAdder.cs

@ -0,0 +1,13 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.ProjectModification
{
public class SolutionModuleAdder : ITransientDependency
{
public async Task AddAsync(string solutionFile, string moduleName)
{
}
}
}

4
framework/src/Volo.Abp.Core/Volo/Abp/Modularity/IAbpModule.cs

@ -1,6 +1,4 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Modularity
{

Loading…
Cancel
Save