Skip to content

Commit

Permalink
Rework default value of command
Browse files Browse the repository at this point in the history
  • Loading branch information
keyroll-99 committed Jun 15, 2024
1 parent 69a5822 commit a53fc95
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fiona.compiler.commandline": {
"version": "0.0.2",
"version": "0.0.4",
"commands": [
"Fiona"
],
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Good to have
- [ ] Console tool
- [X] Create a solution from the console
- [X] Compile one file
- [ ] Compile solution
- [X] Create file with template
- [X] Compile solution
- [ ] Run solution


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>Fiona</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageVersion>0.0.4</PackageVersion>
<PackageVersion>0.0.7</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/Fiona.Compiler.CommandLine/Models/AppArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ namespace Fiona.Compiler.CommandLine.Models;

internal class CreateSolutionArgs
{
[ArgRequired(PromptIfMissing = true), ArgDescription("path to folder"), ArgPosition(1)]
[ArgRequired(PromptIfMissing = true), ArgDescription("path to folder"), ArgExistingDirectory, ArgPosition(1)]
public required string Path { get; init; }

[ArgRequired(PromptIfMissing = true), ArgDescription("name of solution"), ArgPosition(2)]
public required string Name { get; init; }
}

internal class CompileFileArgs
{
[ArgRequired(PromptIfMissing = true), ArgDescription("Patch to file"), ArgPosition(1)]

[ArgRequired(PromptIfMissing = true), ArgDescription("Patch to file"), ArgExistingDirectory, ArgPosition(1)]
public required string PathToFile { get; init; }
[ArgDescription("Path to fsln file (required if file is in different folder)"), ArgPosition(2)]
public string? PathToProject { get; init; }

[ArgDescription("Path to folder with fsln file"), ArgExistingDirectory, ArgPosition(2)]
public string? Project { get; set; }
}

internal class CreateFnFileArgs
{
[ArgDescription("Name of file"), ArgPosition(1)]
public required string Name { get; init; }
[ArgDescription("Path to file location"), ArgPosition(2)]

[ArgDescription("Path to file location"), ArgExistingDirectory, ArgPosition(2)]
public string? Path { get; set; }
[ArgDescription("Path to fsln file (required if file is in different folder)"), ArgPosition(3)]
public string? PathToProject { get; init; }

[ArgDescription("Path to fsln file (required if file is in different folder)"), ArgExistingDirectory, ArgPosition(3)]
public string? PathToProject { get; set; }
}

internal class RunCompilerArg
{
[ArgRequired(PromptIfMissing = true), ArgDescription("Path to fsln file"), ArgPosition(1)]
public required string Project { get; init; }
[ArgDescription("Path to folder with fsln file"), ArgExistingDirectory, ArgPosition(1)]
public string? Project { get; set; }
}
42 changes: 23 additions & 19 deletions compiler/src/Fiona.Compiler.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
using ProjectFile=Fiona.Compiler.ProjectManager.Models.ProjectFile;


List<string> dummyArgs = new()
List<string> createEndpointArgs = new()
{
"CreateEndpoint", "TestFile3", "E:\\100comitow\\ConsoleApp\\FnFiles" , "E:\\100comitow\\ConsoleApp"
"CreateEndpoint", "TestFile3", "E:\\100comitow\\ConsoleApp\\FnFiles", "E:\\100comitow\\ConsoleApp"
};

List<string> dummyArgs2 = new()
List<string> createProjectArgs = new()
{
"Create", "E:\\100comitow\\ConsoleApp", "TestConsole"
};

List<string> compileSolutionArgs = new()
{
"Compile", "E:\\100comitow\\ConsoleApp"
};

//CompileFile E:\100comitow\ConsoleApp\TestFromConsole\aaa.fn E:\100comitow\ConsoleApp
await Args.InvokeActionAsync<FionaCompilerProgram>(dummyArgs.ToArray());
await Args.InvokeActionAsync<FionaCompilerProgram>(compileSolutionArgs.ToArray());

[ArgExceptionBehavior(ArgExceptionPolicy.StandardExceptionHandling)]
internal class FionaCompilerProgram
Expand All @@ -31,7 +36,7 @@ public async Task Create(CreateSolutionArgs arg)
[ArgActionMethod, ArgDescription("Compile one file to c#")]
public async Task CompileFile(CompileFileArgs args)
{
IProjectManager projectManager = await GetProjectManagerForFile(args.PathToFile, args.PathToProject);
IProjectManager projectManager = await GetProject(args.Project);
ProjectFile? projectFile = projectManager.GetFiles().FirstOrDefault(f => f.Path == args.PathToFile);
if (projectFile is null)
{
Expand All @@ -46,7 +51,7 @@ public async Task CreateEndpoint(CreateFnFileArgs args)
{
if (args.Path is null && args.PathToProject is null)
{
throw new Exception("you have to pass one of args: Path, PathToProject");
args.PathToProject = Environment.CurrentDirectory;
}
IProjectManager projectManager;
if (args.Path is null)
Expand All @@ -56,27 +61,26 @@ public async Task CreateEndpoint(CreateFnFileArgs args)
}
else
{
projectManager = await GetProjectManagerForFile(args.Path!, args.PathToProject);
projectManager = await GetProject(args.PathToProject);
}

await projectManager.CreateFileAsync(args.Name, args.Path!);
}

private static async Task<IProjectManager> GetProjectManagerForFile(string pathToFile, string? pathToFslnFile)
[ArgActionMethod, ArgDescription("Compile all fs files to c#")]
public async Task Compile(RunCompilerArg arg)
{
string? pathToProject = pathToFslnFile;
if (string.IsNullOrWhiteSpace(pathToFslnFile))
{
pathToProject = Path.GetDirectoryName(pathToFile);
}
IProjectManager projectManager = await ProjectManagerFactory.GetInstance(pathToProject!);
return projectManager;
arg.Project ??= Environment.CurrentDirectory;
IProjectManager projectManager = await ProjectManagerFactory.GetInstance(arg.Project);
ICompiler compiler = CompilerFactory.Create();
await compiler.RunAsync(projectManager.GetFiles().Select(x => new Fiona.Compiler.Parser.Builders.ProjectFile(x.Name, x.Path)));
}

[ArgActionMethod]
public async Task Test()
private static async Task<IProjectManager> GetProject(string? pathToFslnFile)
{
await Task.CompletedTask;
Console.WriteLine("test");
string pathToProject = pathToFslnFile ?? Environment.CurrentDirectory;
IProjectManager projectManager = await ProjectManagerFactory.GetInstance(pathToProject);
return projectManager;
}

}
12 changes: 11 additions & 1 deletion docs/Fiona-Command-Line.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ eg. `dotnet Fiona Create E:\100Commitow\ConsoleApp TestFromConsole`

## Compile one file

### About Command
### About command

This command compile only one file to csharp. It's create or override exists file `{fileName}.fn.cs`

### How to use it

```dotnet Fiona CompileFile {PathToFile} {PathToFolderWithFsln}```
eg. `dotnet Fiona `

## Compile all fn files

### About command

This command will be, compile all fn files from solution to c# file

### How to use it

```dotnet Fiona Compile {PathToSolution}``` or just ```dotnet Fiona Compile```
21 changes: 11 additions & 10 deletions docs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Welcome to Fiona's documentation, the framework is currently under active develo
1. About
1. [About](About.md)
1. [Getting started](Getting-started.md)
1. [Configuration and AppSettings](Configuration-and-AppSettings.md)
1. [Controller](Controller.md)
1. [Routing](Routing.md)
1. [Middleware](Middleware.md)
1. [Cookie](Cookie.md)
1. [Logger](Logger.md)
1. [Dependency injection](Dependency-injection.md)
1. [Fiona language](Fiona-language.md)
1. [Blueprint](Blueprints.md)
1. [Fiona's language](Fiona-language.md)
2. [Configuration and AppSettings](Configuration-and-AppSettings.md)
3. [Controller](Controller.md)
4. [Routing](Routing.md)
5. [Middleware](Middleware.md)
6. [Cookie](Cookie.md)
7. [Logger](Logger.md)
8. [Dependency injection](Dependency-injection.md)
9. [Fiona language](Fiona-language.md)
10. [Blueprint](Blueprints.md)
11. [Fiona's language](Fiona-language.md)
12. [Fiona command line](Fiona-Command-Line.md)

0 comments on commit a53fc95

Please sign in to comment.