I am currently trying to code an Operating System using the Cosmos user kit (Milestone 4). It's currently a console interface, and I am trying to allow parameters to the commands. The one I seem to be having trouble with is "Help". It's supposed to spit out available commands of different types. For instance, "help/programs" will display commands relating to use of programs.

At this point, my code should be doing this, but when I type "help/programs" or "help/files" or what have you, it doesn't recognize the commands. The commands that don't have any parameters, like shutdown, work fine. Here is my source code:

using System;
using Cosmos.Compiler.Builder;
using System.Collections;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace CosmosBoot1
{
    class Program
    {
        #region Cosmos Builder logic
        // Most users wont touch this. This will call the Cosmos Build tool
        [STAThread]
        static void Main(string[] args)
        {
            BuildUI.Run();
        }
        #endregion
        // Main entry point of the kernel
        public static void Init()
        {
            var xBoot = new Cosmos.Sys.Boot();
            xBoot.Execute();
            while (true)
            {
                string choice = Console.ReadLine();
                string[] spl = choice.Split('/');
                switch (spl[0])
                {
                    case "help":
                        switch (spl[1])
                        {
                            case "programs":
                                Console.WriteLine("Available programs commands are:");
                                Console.WriteLine("Run, Manage, list.");
                                break;
                            case "files":
                                Console.WriteLine("Available files commands are:");
                                Console.WriteLine("Open, Delete, lock, list.");
                                break;
                            default:
                                Console.WriteLine("Astro OS doesn't understand. What is ");
                                Console.Write(spl[1]);
                                Console.Write("?");
                                break;
                        }
                        break;
                    case "shutdown":
                        Cosmos.Sys.Deboot.ShutDown();
                        break;
                    case "reboot":
                        Cosmos.Sys.Deboot.Reboot();
                        break;
                    default:
                        Console.WriteLine("Sorry, Astro OS doesn't recognize that command.");
                        break;
                }
            }
        }
    }
}

I pasted this section into a console app:

while (true)
    {
        string choice = Console.ReadLine();
        string[] spl = choice.Split('/');
        switch (spl[0])
        {
            case "help":
                switch (spl[1])
                {
                    case "programs":
                        Console.WriteLine("Available programs commands are:");
                        Console.WriteLine("Run, Manage, list.");
                        break;
                    case "files":
                        Console.WriteLine("Available files commands are:");
                        Console.WriteLine("Open, Delete, lock, list.");
                        break;
                    default:
                        Console.WriteLine("Astro OS doesn't understand. What is ");
                        Console.Write(spl[1]);
                        Console.Write("?");
                        break;
                }
                break;
        }
    }

And it worked exactly as expected so i would suggest debugging and checking the contents of "spl" when you enter the switch.

Also, please use [code]

[/code] tags when posting code as it preserves the formatting, making it much easier to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.