Skip to content

Commit f2d65b6

Browse files
committed
Adding ReadText CS demo
1 parent a791551 commit f2d65b6

5 files changed

Lines changed: 134 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
src/CommandLine/bin/*
22
src/CommandLine/obj
3-
src/demo/bin/*
4-
src/demo/obj
3+
src/demo/ReadText.Demo/bin/*
4+
src/demo/ReadText.Demo/obj
55
src/CommandLine.Tests/bin/*
66
src/CommandLine.Tests/obj
77
src/CommandLine.FSharp/bin/*

demo/ReadText.Demo/Options.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using CommandLine;
3+
4+
namespace ReadText.Demo
5+
{
6+
abstract class Options
7+
{
8+
[Option('q', "quiet",
9+
HelpText = "Supresses summary messages.")]
10+
public bool Quiet { get; set; }
11+
12+
[Value(0)]
13+
public string FileName { get; set; }
14+
}
15+
16+
[Verb("head", HelpText = "Displays first lines of a file.")]
17+
class HeadOptions : Options
18+
{
19+
[Option('n', "lines",
20+
DefaultValue = 10,
21+
SetName = "amount",
22+
HelpText = "Lines to be printed from the beginning of the file (default 10).")]
23+
public uint Lines { get; set; }
24+
25+
[Option('c', "bytes",
26+
SetName = "amount",
27+
HelpText = "Bytes to be printed from the beginning of the file.")]
28+
public uint Bytes { get; set; }
29+
}
30+
31+
[Verb("tail", HelpText = "Displays last lines of a file.")]
32+
class TailOptions : Options
33+
{
34+
[Option('n', "lines",
35+
DefaultValue = 10,
36+
SetName = "amount",
37+
HelpText = "Lines to be printed from the end of the file (default 10).")]
38+
public uint Lines { get; set; }
39+
40+
[Option('c', "bytes",
41+
SetName = "amount",
42+
HelpText = "Bytes to be printed from the end of the file.")]
43+
public uint Bytes { get; set; }
44+
}
45+
}

demo/ReadText.Demo/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using CommandLine;
5+
using CommandLine.Text;
6+
7+
namespace ReadText.Demo
8+
{
9+
class Program
10+
{
11+
public static void Main(string[] args)
12+
{
13+
var result = Parser.Default.ParseArguments<HeadOptions, TailOptions>(args);
14+
if (result.Errors.Count() > 0)
15+
{
16+
Environment.Exit(1);
17+
}
18+
19+
if (result.Value.GetType () == typeof(HeadOptions))
20+
{
21+
}
22+
23+
// TODO: complete...
24+
}
25+
}
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
[assembly: AssemblyTitle("ReadText.Demo")]
5+
[assembly: AssemblyDescription("ReadText.Demo for Command Line Parser Library")]
6+
[assembly: AssemblyTrademark("")]
7+
#if DEBUG
8+
[assembly: AssemblyConfiguration("Debug")]
9+
#else
10+
[assembly: AssemblyConfiguration("Release")]
11+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>12.0.0</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{F9D3B288-1A73-4C91-8ED7-11ED1704B817}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<RootNamespace>ReadText.Demo</RootNamespace>
11+
<AssemblyName>ReadText.Demo</AssemblyName>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14+
<DebugSymbols>true</DebugSymbols>
15+
<DebugType>full</DebugType>
16+
<Optimize>false</Optimize>
17+
<OutputPath>bin\Debug</OutputPath>
18+
<DefineConstants>DEBUG;</DefineConstants>
19+
<ErrorReport>prompt</ErrorReport>
20+
<WarningLevel>4</WarningLevel>
21+
<Externalconsole>true</Externalconsole>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24+
<DebugType>full</DebugType>
25+
<Optimize>true</Optimize>
26+
<OutputPath>bin\Release</OutputPath>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
<Externalconsole>true</Externalconsole>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<Reference Include="System" />
33+
<Reference Include="System.Core" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Compile Include="Program.cs" />
37+
<Compile Include="Properties\AssemblyInfo.cs" />
38+
<Compile Include="Options.cs" />
39+
<Compile Include="..\SharedAssemblyInfo.cs">
40+
<Link>Properties\SharedAssemblyInfo.cs</Link>
41+
</Compile>
42+
</ItemGroup>
43+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
44+
<ItemGroup>
45+
<ProjectReference Include="..\CommandLine\CommandLine.csproj">
46+
<Project>{E1BD3C65-49C3-49E7-BABA-C60980CB3F20}</Project>
47+
<Name>CommandLine</Name>
48+
</ProjectReference>
49+
</ItemGroup>
50+
</Project>

0 commit comments

Comments
 (0)