Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cli #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/JsonUtils/v14/.suo
Binary file not shown.
1,039 changes: 1,039 additions & 0 deletions .vs/config/applicationhost.config

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions JsonUtils.AutoGen/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>
16 changes: 16 additions & 0 deletions JsonUtils.AutoGen/Example/JsonInput.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones "
}
]
}
82 changes: 82 additions & 0 deletions JsonUtils.AutoGen/JsonUtils.CLI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5943C365-0915-4D35-B763-B74AA4F7C725}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JsonUtils.CLI</RootNamespace>
<AssemblyName>JsonUtils.CLI</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\JsonUtils\ViewModels\IndexViewModel.cs">
<Link>ViewModels\IndexViewModel.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Content Include="Example\JsonInput.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JsonCSharpClassGeneratorLib\JsonClassGeneratorLib.csproj">
<Project>{7bef7eaa-de37-40fb-bd33-3def0685031f}</Project>
<Name>JsonClassGeneratorLib</Name>
</ProjectReference>
<ProjectReference Include="..\JsonUtils.Core\JsonUtils.Core.csproj">
<Project>{d7dae321-e824-4487-82bd-417152c41ffd}</Project>
<Name>JsonUtils.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
94 changes: 94 additions & 0 deletions JsonUtils.AutoGen/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using CommandLine;
using CommandLine.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using JsonUtils.Core;

namespace JsonUtils.CLI
{
class Program
{
static void Main(string[] args)
{
var options = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, options))
{
// Values are available here
if (options.Verbose) Console.WriteLine("Reading json schema at : {0}", options.InputFile);

if(! File.Exists(options.InputFile))
{
if (options.Verbose)
{
Console.WriteLine("The file does not exists");
}else
{
throw new FileNotFoundException("The json file does not exists");
}
}
//JsonUtils.Core.Language
JsonUtils.Core.Language Language = (JsonUtils.Core.Language)Enum.Parse(typeof(JsonUtils.Core.Language), options.GenerateLang, true);

if (options.Verbose) Console.WriteLine("Reading the file ...");
var jsonInput = File.ReadAllText(options.InputFile).Trim() ;

if (options.Verbose) Console.WriteLine("Generating the code ...");
var output = CodeGenerationHelper.Prepare(jsonInput, options.RootObject, Language, options.NameSpace, false,
"None", (JsonUtils.Core.Language.Java == Language || JsonUtils.Core.Language.PHP == Language) && true);

if(string.IsNullOrEmpty(options.OutputFile))
{
Console.Write(output);
}else
{
if (options.Verbose) Console.WriteLine("Saving the code");
File.WriteAllText(options.OutputFile, output);
if (options.Verbose) Console.WriteLine("Saved to "+ options.OutputFile);
}

}


}


}

class Options
{
[Option('i', "input", Required = true,
HelpText = "Input json schema file to be processed.")]
public string InputFile { get; set; }

[Option('o', "output", Required = false,
HelpText = "Output file to be generated, will output to console if not supplied.")]
public string OutputFile { get; set; }
[Option('n', "namespace", Required = false,
HelpText = "the namespace used")]
public string NameSpace { get; set; }

[Option('r',"root",Required =true, HelpText ="The root name of the object, Eg. Person")]
public string RootObject { get; set; }
[Option('g', "gen", Required = true, HelpText = "The language generated, eg. c#, typescript, java")]
public string GenerateLang { get; set; }

// omitting long name, default --verbose
[Option(DefaultValue = true,
HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }

[ParserState]
public IParserState LastParserState { get; set; }

[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this,
(HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
}
36 changes: 36 additions & 0 deletions JsonUtils.AutoGen/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("JsonUtils.AutoGen")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JsonUtils.AutoGen")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5943c365-0915-4d35-b763-b74aa4f7c725")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added JsonUtils.AutoGen/bin/Debug/CommandLine.dll
Binary file not shown.
Loading