Skip to content

Commit dc6e9f8

Browse files
committed
introduced the view model and removed the console property from the command.
1 parent 7216a37 commit dc6e9f8

File tree

117 files changed

+1472
-575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1472
-575
lines changed

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/DefaultCommand.cs renamed to sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/Default/DefaultCommand.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Default;
1818

1919
[AnonymousCommand(Description = "Default command to be executed when no command name is specified.")]
20-
public class DefaultCommand : ConsoleCommandBase
20+
public class DefaultCommand : IConsoleCommand<DefaultViewModel>
2121
{
22-
[NamedParameter("text")]
22+
[NamedParameter("text", ShortName = 't')]
2323
public string Text { get; set; }
2424

25-
public DefaultCommand(EnhancedConsole enhancedConsole)
26-
: base(enhancedConsole)
25+
public Task<DefaultViewModel> Execute()
2726
{
28-
}
29-
30-
public override Task Execute()
31-
{
32-
Console.WriteTitle("Default command");
33-
Console.WriteValue("Text", Text);
27+
DefaultViewModel viewModel = new()
28+
{
29+
Text = Text
30+
};
3431

35-
return Task.CompletedTask;
32+
return Task.FromResult(viewModel);
3633
}
3734
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ConsoleTools.Commando
2+
// Copyright (C) 2022-2023 Dust in the Wind
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Default;
18+
19+
public class DefaultView : ViewBase<DefaultViewModel>
20+
{
21+
public override void Display(DefaultViewModel viewModel)
22+
{
23+
WriteTitle("Default command");
24+
WriteValue("Text", viewModel.Text);
25+
}
26+
}

sources/ConsoleTools.Commando/ConsoleCommandBase.cs renamed to sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/Default/DefaultViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
namespace DustInTheWind.ConsoleTools.Commando;
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Default;
1818

19-
public abstract class ConsoleCommandBase : ConsoleCommandBase<EnhancedConsole>
19+
public class DefaultViewModel
2020
{
21-
protected ConsoleCommandBase(EnhancedConsole console)
22-
: base(console)
23-
{
24-
}
21+
public string Text { get; set; }
2522
}

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/DummyCommand.cs renamed to sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/Dummy/DummyCommand.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Dummy;
1818

1919
[NamedCommand("dummy", Description = "A dummy command that shows how to create parameters of different types.")]
20-
public class DummyCommand : ConsoleCommandBase
20+
public class DummyCommand : IConsoleCommand<DummyViewModel>
2121
{
2222
[NamedParameter("text", ShortName = 't', IsOptional = true, Description = "A simple text.")]
2323
public string Text { get; set; }
@@ -43,33 +43,20 @@ public class DummyCommand : ConsoleCommandBase
4343
[AnonymousParameter(Order = 2, IsOptional = true, Description = "An anonymous number. It is identified based on its index in the list of arguments.")]
4444
public int? Param2 { get; set; }
4545

46-
public DummyCommand(EnhancedConsole console)
47-
: base(console)
46+
public Task<DummyViewModel> Execute()
4847
{
49-
}
50-
51-
public override Task Execute()
52-
{
53-
Console.WriteTitle("Dummy Command");
54-
55-
Console.WithIndentation("Initial values:", () =>
48+
DummyViewModel result = new()
5649
{
57-
Console.WriteValue("Text", Text);
58-
Console.WriteValue("Flag", Flag);
59-
Console.WriteValue("Integer Number", IntegerNumber);
60-
Console.WriteValue("Real Number", RealNumber);
61-
Console.WriteValue("Character", Character);
62-
Console.WriteValue("Param 1", Param1);
63-
Console.WriteValue("Param 2", Param2);
64-
});
65-
Console.WriteLine();
66-
67-
Text = "This is a new text.";
68-
Flag = false;
69-
IntegerNumber = 184603;
70-
RealNumber = 3.141592653f;
71-
Character = '╢';
72-
73-
return Task.CompletedTask;
50+
Text = Text,
51+
Flag = Flag,
52+
Flag2 = Flag2,
53+
IntegerNumber = IntegerNumber,
54+
RealNumber = RealNumber,
55+
Character = Character,
56+
Param1 = Param1,
57+
Param2 = Param2
58+
};
59+
60+
return Task.FromResult(result);
7461
}
7562
}

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/DummyView.cs renamed to sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/Dummy/DummyView.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Dummy;
1818

19-
public class DummyView : ViewBase<DummyCommand>
19+
public class DummyView : ViewBase<DummyViewModel>
2020
{
21-
public override void Display(DummyCommand dummyCommand)
21+
public override void Display(DummyViewModel viewModel)
2222
{
23-
WithIndentation("Same values after command finished execution:", () =>
23+
WithIndentation("The result of the command execution:", () =>
2424
{
25-
WriteValue("Text", dummyCommand.Text);
26-
WriteValue("Flag", dummyCommand.Flag);
27-
WriteValue("Integer Number", dummyCommand.IntegerNumber);
28-
WriteValue("Real Number", dummyCommand.RealNumber);
29-
WriteValue("Character", dummyCommand.Character);
30-
WriteValue("Param 1", dummyCommand.Param1);
31-
WriteValue("Param 2", dummyCommand.Param2);
25+
WriteValue("Text", viewModel.Text);
26+
WriteValue("Flag", viewModel.Flag);
27+
WriteValue("Integer Number", viewModel.IntegerNumber);
28+
WriteValue("Real Number", viewModel.RealNumber);
29+
WriteValue("Character", viewModel.Character);
30+
WriteValue("Param 1", viewModel.Param1);
31+
WriteValue("Param 2", viewModel.Param2);
3232
});
3333
}
3434
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ConsoleTools.Commando
2+
// Copyright (C) 2022-2023 Dust in the Wind
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Dummy;
18+
19+
public class DummyViewModel
20+
{
21+
public string Text { get; set; }
22+
23+
public bool Flag { get; set; }
24+
25+
public bool Flag2 { get; set; }
26+
27+
public int IntegerNumber { get; set; }
28+
29+
public float RealNumber { get; set; }
30+
31+
public char Character { get; set; }
32+
33+
public string Param1 { get; set; }
34+
35+
public int? Param2 { get; set; }
36+
}

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/ReadFileCommand.cs renamed to sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/ReadFile/ReadFileCommand.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,29 @@
1616

1717
using System.Text;
1818

19-
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
19+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.ReadFile;
2020

2121
[NamedCommand("read", Description = "Display the content of a text file.")]
22-
public class ReadFileCommand : ConsoleCommandBase
22+
public class ReadFileCommand : IConsoleCommand<ReadFileViewModel>
2323
{
24-
[AnonymousParameter(Order = 1, Description = "The path to the file that should be displayed.")]
24+
[AnonymousParameter(Order = 1, DisplayName = "file path", Description = "The path to the file that should be displayed.")]
2525
public string FilePath { get; set; }
2626

2727
[NamedParameter("encoding", ShortName = 'e', IsOptional = true, Description = "The text encoding to be used when reading the file.")]
2828
public Encoding Encoding { get; set; }
2929

30-
public ReadFileCommand(EnhancedConsole console)
31-
: base(console)
30+
public Task<ReadFileViewModel> Execute()
3231
{
33-
}
34-
35-
public override Task Execute()
36-
{
37-
Console.WriteTitle("Reading a text file");
38-
Console.WriteValue("File", FilePath);
39-
4032
string content = Encoding == null
4133
? File.ReadAllText(FilePath)
4234
: File.ReadAllText(FilePath, Encoding);
4335

44-
Console.WriteValueBelowName("Content", content);
36+
ReadFileViewModel viewModel = new()
37+
{
38+
FilePath = FilePath,
39+
Content = content
40+
};
4541

46-
return Task.CompletedTask;
42+
return Task.FromResult(viewModel);
4743
}
4844
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ConsoleTools.Commando
2+
// Copyright (C) 2022-2023 Dust in the Wind
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.ReadFile;
18+
19+
internal class ReadFileView : ViewBase<ReadFileViewModel>
20+
{
21+
public override void Display(ReadFileViewModel viewModel)
22+
{
23+
WriteTitle("Reading a text file");
24+
WriteValue("File", viewModel.FilePath);
25+
WriteValueBelowName("Content", viewModel.Content);
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ConsoleTools.Commando
2+
// Copyright (C) 2022-2023 Dust in the Wind
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.ReadFile;
18+
19+
public class ReadFileViewModel
20+
{
21+
public string FilePath { get; set; }
22+
23+
public string Content { get; set; }
24+
}

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
using DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
17+
using DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands.Dummy;
1818
using DustInTheWind.ConsoleTools.Commando.Setup.Autofac;
1919

2020
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder;

0 commit comments

Comments
 (0)