示例#1
0
文件: ConsoleUi.cs 项目: FizzyP/guru
        Item parseAddCommand(string[] args, ref int idx)
        {
            if (args.Length <= idx)
            {
                Console.WriteLine("Expected description.");
                displayAddCommandInstructions();
                return(null);
            }
            var description = args[idx++];

            var newId = ItemGroup.allocateId();
            var item  = new Item(newId, description);

            addItem(item);
            this.ItemGroupFile.save();
            return(item);
        }
示例#2
0
文件: ConsoleUi.cs 项目: FizzyP/guru
        //  If x is a number, finds the task with that id
        //      returns null if it doesn't exist.
        //  If x is a string makes a new task with that description
        Item createOrGetItemFromIdOrString(string x)
        {
            Item newItem;

            //  Extract an id or description
            UInt32 itemId;

            if (UInt32.TryParse(x, out itemId))
            {
                //  It's a task id
                newItem = ItemGroup.Items.getItemById(itemId);
                //  Assume newItem isn't null because we checked above
            }
            else
            {
                //  Createa a new item based on description and add it to the item group
                newItem = new Item(ItemGroup.allocateId(), x);
                addItem(newItem);
            }

            return(newItem);
        }
示例#3
0
文件: ConsoleUi.cs 项目: FizzyP/guru
        void handleDepMethod(Item item, string[] args, ref int idx)
        {
            if (args.Length <= idx)
            {
                printDepMethodErrorMessage();
                return;
            }

            try
            {
                var id    = UInt64.Parse(args[idx]);
                var item2 = ItemGroup.getItemById(id);
                addDependency(item, item2);
                ItemGroupFile.save();
                return;
            }
            catch
            {
                printDepMethodErrorMessage();
                return;
            }
        }
示例#4
0
 private ItemGroupFile(string path, ItemGroup group)
 {
     Path = path;
     ItemGroup = group;
 }
示例#5
0
文件: ConsoleUi.cs 项目: FizzyP/guru
        public void parseArgs(string[] args)
        {
            if (args.Length == 0)
            {
                handleEmptyArgs();
                return;
            }

            int idx = 0;

            switch (args[0])
            {
            case "prompt":
            case "p":
            {
                enterPromptLoop();
                break;
            }

            case "help": {
                printHelp();
                return;
            }

            case "next": {
                idx++;
                parseNextCommand(args, ref idx);
                return;
            }

            case "add":
            case "a":
            {
                idx++;
                parseAddCommand(args, ref idx);
                return;
            }

            case "chain":
            case "c":
            {
                idx++;
                parseChainCommand(args, ref idx);
                return;
            }

            case "group":
            case "g":
            {
                idx++;
                parseGroupCommand(args, ref idx);
                return;
            }


            case "remove":
            case "rm":
            {
                idx++;
                parseRemoveCommand(args, ref idx);
                return;
            }

            case "rename":
            case "rn":
            {
                idx++;
                parseRenameCommand(args, ref idx);
                return;
            }

            case "list":
            case "l":
            {
                idx++;
                parseListCommand(args, ref idx);
                return;
            }

            case "tree":
            case "t":
            {
                idx++;
                parseTreeCommand(args, ref idx);
                return;
            }

            case "skip":
            case "s":
            {
                idx++;
                handleSkipCommand(args, ref idx);
                return;
            }

            case "done":
            case "d":
            {
                idx++;
                handleDoneCommand(args, ref idx);
                return;
            }

            case "comment":
            {
                idx++;
                handleCommentCommand(args, ref idx);
                return;
            }

            default: {
                if (args[0].Length > 0)
                {
                    //	Queries
                    if (args[0][0] == '?')
                    {
                        idx++;
                        handleQuery(args[0], args, ref idx);
                        return;
                    }
                    else
                    {
                        //	Methods on Items
                        var idStr = args[0];
                        try {
                            UInt64 idNum = UInt64.Parse(idStr);
                            var    item  = ItemGroup.getItemById(idNum);
                            idx++;
                            handleMethodOnItem(item, args, ref idx);
                            return;
                        }
                        catch {
                            Console.WriteLine("Expecting a keyword or an item id number.  Found \"" + args[0] + "\" instead.");
                            return;
                        }
                    }
                }
                return;
            }
            }
        }
示例#6
0
 private ItemGroupFile(string path, ItemGroup group)
 {
     Path      = path;
     ItemGroup = group;
 }