Skip to content

Commit db0724d

Browse files
Merge pull request #1 from Azure/dev/abhishekkuma/creating_dotnet_console_app
Hawaii-Cli tool to generate config for runtime Engine
2 parents 7c313ce + 6318ecf commit db0724d

File tree

11 files changed

+814
-24
lines changed

11 files changed

+814
-24
lines changed

Hawaii-Cli/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
##
4+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5+
6+
# Generated Files
7+
/bin
8+
/obj
9+
10+
# Local History for Visual Studio
11+
.localhistory/
12+
.vs/
13+
/.vscode
14+
*.code-workspace
15+
16+
# Nuget package
17+
/nupkg
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using CommandLine;
4+
using CommandLine.Text;
5+
6+
namespace Hawaii.Cli.Classes
7+
{
8+
public class CommandLineHelp
9+
{
10+
11+
/// <summary>
12+
/// For displaying help with a command argument of --help
13+
/// </summary>
14+
public static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
15+
{
16+
17+
var help = HelpText.AutoBuild(result, helpText =>
18+
{
19+
helpText.AdditionalNewLineAfterOption = false;
20+
helpText.Heading = "See all the available options";
21+
22+
return HelpText.DefaultParsingErrorsHandler(result, helpText);
23+
24+
}, e => e);
25+
26+
Console.WriteLine(help);
27+
Environment.Exit(0);
28+
}
29+
30+
/// <summary>
31+
/// Parse command line for expected arguments
32+
/// </summary>
33+
/// <param name="args">incoming program arguments</param>
34+
public static void ParseArguments(string[] args)
35+
{
36+
Parser parser = new CommandLine.Parser(with => with.HelpWriter = null);
37+
38+
ParserResult<CommandLineOptions> results = parser.ParseArguments<CommandLineOptions>(args);
39+
40+
var command = args.AsQueryable().FirstOrDefault();
41+
string entity = "";
42+
43+
switch (command)
44+
{
45+
case "init":
46+
results.WithParsed<CommandLineOptions>(Operations.Init)
47+
.WithNotParsed(errors => CommandLineHelp.DisplayHelp(results, errors));
48+
break;
49+
50+
case "add":
51+
entity = args.AsQueryable().ElementAt(1);
52+
results.WithParsed<CommandLineOptions>(opt => Operations.Add(entity, opt))
53+
.WithNotParsed(errors => CommandLineHelp.DisplayHelp(results, errors));
54+
break;
55+
56+
case "update":
57+
entity = args.AsQueryable().ElementAt(1);
58+
results.WithParsed<CommandLineOptions>(opt => Operations.Update(entity, opt))
59+
.WithNotParsed(errors => CommandLineHelp.DisplayHelp(results, errors));
60+
break;
61+
62+
default:
63+
results.WithNotParsed(errors => CommandLineHelp.DisplayHelp(results, errors));
64+
Console.WriteLine($"ERROR: Could not execute because the specified command was not found.");
65+
Console.WriteLine("please do init to initialize the config file.");
66+
break;
67+
68+
}
69+
70+
}
71+
}
72+
73+
74+
75+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using CommandLine;
3+
4+
namespace Hawaii.Cli.Classes
5+
{
6+
public sealed class CommandLineOptions
7+
{
8+
[Option('n', "name", Required = false, HelpText = "file name")]
9+
public String? name { get; set; }
10+
11+
[Option("database-type", Required = false, HelpText = "Type of database to connect")]
12+
public String? databaseType { get; set; }
13+
14+
[Option("connection-string", Required = false, HelpText = "Connection details to connect to database")]
15+
public String? connectionString { get; set; }
16+
17+
//TODO: Link options with Specidied commands
18+
// we need to make sure certain options are only required with certain commands.
19+
// for example: source is required only with add/update and not init
20+
21+
[Option('s', "source", Required = false, HelpText = "name of the table")]
22+
public String? source { get; set; }
23+
24+
[Option("rest", Required = false, HelpText = "route for rest api")]
25+
public String? restRoute { get; set; }
26+
27+
[Option("graphql", Required = false, HelpText = "Type of graphQL")]
28+
public String? graphQLType { get; set; }
29+
30+
[Option("permission", Required = false, HelpText = "permission required to acess source table")]
31+
public String? permission { get; set; }
32+
33+
[Option("fields.include", Required = false, HelpText = "fields that are allowed access to permission")]
34+
public String? fieldsToInclude { get; set; }
35+
36+
[Option("fields.exclude", Required = false, HelpText = "fields that are excluded from the action lists")]
37+
public String? fieldsToExclude { get; set; }
38+
39+
[Option("relationship", Required = false, HelpText = "specify relationship between two entities")]
40+
public String? relationship { get; set; }
41+
42+
[Option("target.entity", Required = false, HelpText = "specify relationship between two entities")]
43+
public String? targetEntity { get; set; }
44+
45+
[Option("cardinality", Required = false, HelpText = "specify relationship between two entities")]
46+
public String? cardinality { get; set; }
47+
48+
[Option("mapping.fields", Required = false, HelpText = "specify relationship between two entities")]
49+
public String? mappingFields { get; set; }
50+
51+
[Option(Default = false, HelpText = "Prints all messages to standard output.")]
52+
public bool Verbose { get; set; }
53+
54+
}
55+
}

0 commit comments

Comments
 (0)