Skip to content

Commit

Permalink
add hostname and ls commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoder04 committed Jan 29, 2022
1 parent cf41849 commit 4e29c74
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
21 changes: 21 additions & 0 deletions hostname.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.IO;
using System.Net;
using ILeoConsole;
using ILeoConsole.Plugin;
using ILeoConsole.Core;

namespace LeoConsole_ExamplePlugin {
public class Hostname : ICommand {
public string Name { get { return "hostname"; } }
public string Description { get { return "print computer's hostname"; } }
public Action CommandFunktion { get { return () => Command(); } }
private string[] _InputProperties;
public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }

public void Command() {
Console.WriteLine(Dns.GetHostName());
}
}
}

// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab
42 changes: 42 additions & 0 deletions ls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.IO;
using ILeoConsole;
using ILeoConsole.Plugin;
using ILeoConsole.Core;

namespace LeoConsole_ExamplePlugin {
public class Ls : ICommand {
public string Name { get { return "ls"; } }
public string Description { get { return "list contents of a folder"; } }
public Action CommandFunktion { get { return () => Command(); } }
private string[] _InputProperties;
public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }
public IData data = new ConsoleData();

public void Command() {
if (_InputProperties.Length < 2) {
ls(data.SavePath);
return;
}
for (int i = 1; i < _InputProperties.Length; i++) {
ls(_InputProperties[i]);
Console.Write("\n");
}
}

private void ls(string directory) {
Console.WriteLine(directory + ":");
try {
foreach (string filename in Directory.GetDirectories(directory)) {
Console.WriteLine(Path.GetFileName(filename) + "/");
}
foreach (string filename in Directory.GetFiles(directory)) {
Console.WriteLine(Path.GetFileName(filename));
}
} catch (Exception e) {
Console.WriteLine("error: " + e.Message);
}
}
}
}

// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab
4 changes: 3 additions & 1 deletion plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public void PluginMain() {

_Commands = new List<ICommand>();
_Commands.Add(new Basename());
_Commands.Add(new Cat());
_Commands.Add(new Clear());
_Commands.Add(new Echo());
_Commands.Add(new Hostname());
_Commands.Add(new Ls());
_Commands.Add(new Yes());
_Commands.Add(new Cat());
}
}
}
Expand Down

0 comments on commit 4e29c74

Please sign in to comment.