OSDN Git Service

na-get-lib,UserAgentをアセンブリバージョンなどから取得するよう変更
[applistation/AppliStation.git] / all-get / Main.cs
index 98b1a44..a4be970 100644 (file)
 using System;\r
 using System.IO;\r
 using System.Collections.Generic;\r
-using NaGet.Net;\r
 using NaGet.Packages;\r
 using NaGet.Packages.Install;\r
 using NaGet.SubCommands;\r
+using NaGet.Tasks;\r
 \r
 namespace AllGet\r
 {\r
-\r
-       class DownloadListener\r
+       sealed class TaskSetEventHandlers\r
        {\r
-               private string line = null;\r
+               public static void OnTaskSetEvent(object sender, TaskEventArgs e) { \r
+                       switch (e.Type) {\r
+//                             case NaGetTaskSetEventType.COMPLETED_TASKSET\r
+//                                     break;\r
+                               case TaskEventType.COMPLETED:\r
+                                       Console.WriteLine("Done.");\r
+                                       break;\r
+                               case TaskEventType.STARTED_SUBTASK:\r
+                                       Console.Write("  " + e.TaskMessage);\r
+                                       break;\r
+                               case TaskEventType.COMPLETED_SUBTASK:\r
+                                       Console.WriteLine(" ... Done. [{0}%]", (int) e.ProgressPercent);\r
+                                       break;\r
+                               case TaskEventType.INFO:\r
+                                       Console.WriteLine("  " + e.TaskMessage);\r
+                                       break;\r
+                               case TaskEventType.ERROR:\r
+                               case TaskEventType.WARNING:\r
+                                       Console.WriteLine("  [Error]" + e.TaskMessage);\r
+                                       break;\r
+                       }\r
+               }\r
                \r
-               /// <summary>\r
-               /// lineのコンソール上における長さ\r
-               /// </summary>\r
-               private int lineWidth = 0;\r
-       \r
-               public void OnDownload(object sender, DownloadEventArgs a) {\r
-                       if (line != null) {\r
-                               lock (line) {\r
-                                       int newpos = (lineWidth <= 0)? 0 : Console.CursorLeft - lineWidth;\r
-                                       if (newpos < 0) newpos = 0;\r
-                                       \r
-                                       // 空白で埋める\r
-                                       Console.CursorLeft = newpos;\r
-                                       for (int i = 0; i < lineWidth && Console.CursorLeft < Console.BufferWidth; i++) {\r
-                                               Console.Write(' ');\r
-                                       }\r
-                                       Console.CursorLeft = newpos;\r
-                                       \r
-                                       line = null; lineWidth = 0;\r
+               public static void OnDownloadSubTaskEvent(object sender, TaskEventArgs e)\r
+               {\r
+                       if (sender is NaGet.SubCommands.SubTask.DownloadSubTask) {\r
+                               if (e.Type == TaskEventType.STARTED) {\r
+                                       Console.WriteLine();\r
+                               }\r
+                               \r
+                               int origPosX = Console.CursorLeft;\r
+                               for (int i = 0; i < Console.WindowWidth - 1; i++) {\r
+                                       Console.Write(' ');\r
+                               }\r
+                               Console.CursorLeft = origPosX;\r
+                               \r
+                               switch (e.Type) {\r
+                                       case TaskEventType.PING:\r
+                                               {\r
+                                                       int origPos = Console.CursorLeft;\r
+                                                       Console.Write(e.TaskMessage);\r
+                                                       Console.CursorLeft = origPos;\r
+                                               }\r
+                                               break;\r
+                                       case TaskEventType.WARNING:\r
+                                       case TaskEventType.ERROR:\r
+                                               Console.WriteLine("  [Error]" + e.TaskMessage);\r
+                                               break;\r
+                                       default:\r
+                                               Console.WriteLine(e.TaskMessage);\r
+                                               break;\r
                                }\r
                        }\r
-                       \r
-                       switch (a.Type) {\r
-                       case DownloadEventType.INITED:\r
-                               line = "starting...";\r
-                               break;\r
-                       case DownloadEventType.CONNECTED:\r
-                       case DownloadEventType.DOWNLOADING:\r
-                               line = a.TaskMessage;\r
-                               break;\r
-                       case DownloadEventType.COMPLETED:\r
-                               //\r
-                               line = null;\r
-                               break;\r
-                       case DownloadEventType.ERROR:\r
-                               Console.Write("interrupted! ERROR!");\r
-                               line = null;\r
-                               break;\r
+               }\r
+               \r
+               public static NaGetTaskQueryResult OnTaskQueryEvent(object sender, NaGetTaskQueryArgs e)\r
+               {\r
+                       char result = '\u0000';\r
+                       if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
+                               result = AllGet.Util.Query(e.Message + " [y/R/n]?", "yrn", 'r');\r
+                       } else if (e.SelectionFlag == (NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
+                               result = AllGet.Util.Query(e.Message + " [R/n]?", "rn", 'r');\r
+                       } else if (e.SelectionFlag == NaGetTaskQueryResult.CONTINUE) {\r
+                               result = AllGet.Util.Query(e.Message + " [Y]?", "y", 'y');\r
+                       } else {\r
+                               result = AllGet.Util.Query(e.Message + " [Y/n]?", "yn", 'y');\r
                        }\r
                        \r
-                       if (line != null) {\r
-                               int posOld = Console.CursorLeft;\r
-                               Console.Write(line);\r
-                               lineWidth = Console.CursorLeft - posOld;\r
+                       switch (result) {\r
+                               case 'y':\r
+                                       return NaGetTaskQueryResult.CONTINUE;\r
+                               case 'n':\r
+                                       return NaGetTaskQueryResult.CANCEL;\r
+                               case 'r':\r
+                                       return NaGetTaskQueryResult.RETRY;\r
+                               default:\r
+                                       return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
                        }\r
                }\r
        }\r
-\r
+       \r
+       \r
        class MainClass\r
        {\r
-               private Downloader downloader;\r
-               \r
                private PackageListsManager pkgListMan;\r
                \r
+               /// <summary>\r
+               /// サイレントインストールをするか否か\r
+               /// </summary>\r
+               private bool silent = false;\r
+               \r
                public MainClass()\r
                {\r
-                       downloader = new Downloader();\r
-                       DownloadListener dl = new DownloadListener();\r
-                       downloader.DownloadEventRaised += new EventHandler<DownloadEventArgs>(dl.OnDownload);\r
-                       \r
                        pkgListMan = new PackageListsManager();\r
+                       pkgListMan.LoadPackageLists();\r
                }\r
                \r
                public void Update()\r
@@ -89,65 +120,32 @@ namespace AllGet
                \r
                public void update(bool downloadPackageListFlag)\r
                {\r
-                       NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag);\r
-                       tasks.Downloader = this.downloader;\r
-                       tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
-                               switch (e.Type) {\r
-//                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
-//                                             break;\r
-                                       case NaGetTaskSetEventType.COMPLETED:\r
-                                               Console.WriteLine("Done.");\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.STARTED_TASKSET:\r
-                                               Console.Write("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
-                                               Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.INFO:\r
-                                               Console.WriteLine("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.ERROR:\r
-                                       case NaGetTaskSetEventType.WARNING:\r
-                                               Console.WriteLine("  [Error]" + e.TaskMessage);\r
-                                               break;\r
-                               }\r
-                       };\r
+                       NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListMan, downloadPackageListFlag);\r
+                       tasks.TaskEventRaised += TaskSetEventHandlers.OnTaskSetEvent;\r
+                       tasks.SubTaskEventRaised += TaskSetEventHandlers.OnDownloadSubTaskEvent;\r
                        \r
                        tasks.Run();\r
                }\r
                \r
                public void CheckUpgrade()\r
                {\r
-                       PackageList<Package> packageList = pkgListMan.AvailablePkgList;\r
-                       \r
-                       VersionComparetor verComp = new VersionComparetor();\r
-                       \r
-                       foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList.Packages) {\r
-                               Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
+                       foreach (Package pkg in UpgradeFinder.GetUpgradePackages(pkgListMan)) {\r
+                               bool isSystem = false;\r
+                               Package instPkg = null;\r
                                \r
-                               if (avaiablePkg != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           pkgListMan.InstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               Console.ForegroundColor = ConsoleColor.Green;\r
+                               instPkg = pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name);\r
+                               if (instPkg != null) {\r
+                                       isSystem = true;\r
+                               } else {\r
+                                       instPkg = pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name);\r
+                                       if (instPkg != null) {\r
+                                               isSystem = false;\r
+                                       } else {\r
+                                               System.Diagnostics.Debug.Fail("internal error.");\r
                                        }\r
-                                       \r
-                                       Console.WriteLine("{0} ({1}) => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
-                                       Console.ResetColor();\r
                                }\r
-                       }\r
-                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
-                               Package avaiablePkg = packageList.GetPackageForName(pkg.Name);\r
                                \r
-                               if (avaiablePkg != null) {\r
-                                       if (verComp.Compare(pkg.Version, avaiablePkg.Version) < 0 &&\r
-                                           pkgListMan.SystemInstalledPkgList.GetPackageForPackage(pkg.Name, avaiablePkg.Version) == null) {\r
-                                               Console.ForegroundColor = ConsoleColor.Green;\r
-                                       }\r
-                                       \r
-                                       Console.WriteLine("{0} ({1})@sys => ({2})", pkg.Name, pkg.Version, avaiablePkg.Version);\r
-                                       Console.ResetColor();\r
-                               }\r
+                               Console.WriteLine("{0} ({1}){3} => ({2})", pkg.Name, instPkg.Version, pkg.Version, (isSystem)? "@sys" : "");\r
                        }\r
                }\r
                \r
@@ -174,11 +172,13 @@ namespace AllGet
                        foreach (Package pkg in allPkgs.GetPackagesForName(packagename)) {\r
                                Console.WriteLine("Package: {0}", pkg.Name);\r
                                Console.WriteLine("Version: {0}", pkg.Version);\r
+                               Console.WriteLine("Summary: {0}", pkg.Summary);\r
                                if (pkg.Url != null) Console.WriteLine("Website: {0}", pkg.Url.Href);\r
                                if (pkg.Tags != null) Console.WriteLine("Tag: {0}", pkg.Tags.ToLower());\r
                                Console.WriteLine("Type: {0}", pkg.Type);\r
                                if (pkg.License != null) Console.WriteLine("License: {0}", pkg.License);\r
                                if (pkg is InstalledPackage) Console.WriteLine("State: Installed");\r
+                               Console.WriteLine("Repository: {0}", pkg.PackageListName);\r
                                \r
                                if (pkg.Description != null) {\r
                                        Console.WriteLine("Description:");\r
@@ -188,6 +188,7 @@ namespace AllGet
                        }\r
                }\r
                \r
+               \r
                public void Download(string[] packagenames)\r
                {\r
                        Installation[] installations = null;\r
@@ -207,7 +208,7 @@ namespace AllGet
                                \r
                                installations = new Installation[downloadList.Count];\r
                                for (int i = 0; i < installations.Length; i++) {\r
-                                       installations[i] = new Installation((Package) downloadList[i]);\r
+                                       installations[i] = new Installation(downloadList[i]);\r
                                }\r
                        }\r
                        \r
@@ -218,35 +219,12 @@ namespace AllGet
                                Environment.Exit(0);\r
                        }\r
                        \r
-                       {\r
-                               int i = 0;\r
-                               foreach (Installation inst in installations) {\r
-                                       i++;\r
-                                       \r
-                                       if (! inst.IsInstallablePackage()) {\r
-                                               Console.WriteLine("E:{0} {1} can not be installed.", i, inst.ToString());\r
-                                               continue;\r
-                                       }\r
-                                       \r
-                                       try {\r
-                                               Console.Write("Get:{0} {1}", i, inst.ToString());\r
-                                               inst.Download(downloader);\r
-                                               Console.WriteLine(" ...Done");\r
-                                       } catch (Exception e) {\r
-                                               Console.WriteLine("E: "+e.Message);\r
-                                               throw new ApplicationException(string.Format("Failed to download {0}", inst.ToString()), e);\r
-                                       }\r
-                               }\r
-                               \r
-                               i = 0;\r
-                               foreach (Installation inst in installations) {\r
-                                       i++;\r
-                                       \r
-                                       if (inst.IsInstallablePackage() && inst.VerifyHashValues() == false) {\r
-                                               Console.WriteLine("Verify:{0} {1} does not match hash value!", i, inst.ToString());\r
-                                       }\r
-                               }\r
-                       }\r
+                       NaGet.SubCommands.NaGetDownloadToCache2 tasks = new NaGet.SubCommands.NaGetDownloadToCache2(pkgListMan, installations);\r
+                       tasks.TaskEventRaised += TaskSetEventHandlers.OnTaskSetEvent;\r
+                       tasks.SubTaskEventRaised += TaskSetEventHandlers.OnDownloadSubTaskEvent;\r
+                       tasks.TaskQueryRaised += TaskSetEventHandlers.OnTaskQueryEvent;\r
+                       \r
+                       tasks.Run();\r
                }\r
                \r
                public void Install(string[] packagenames)\r
@@ -272,15 +250,17 @@ namespace AllGet
                                \r
                                installations = new Installation[downloadList.Count];\r
                                for (int i = 0; i < installations.Length; i++) {\r
-                                       installations[i] = new Installation((Package) downloadList[i]);\r
-                                       \r
-                                       if (! installations[i].IsInstallablePackage()) {\r
-                                               Console.WriteLine("E: Can not install package {0} to your PC.", installations[i].ToString());\r
-                                               Environment.Exit(1);\r
-                                       }\r
+                                       installations[i] = new Installation(downloadList[i]);\r
                                }\r
                        }\r
                        \r
+                       Installation[] depInstallations;\r
+                       {\r
+                               Installation[] resolved;\r
+                               DependeciesResolver.ResolveInstallations(installations, pkgListMan, out resolved, out depInstallations);\r
+                               installations = resolved;\r
+                       }\r
+                       \r
                        Console.WriteLine("The following packages will be downloaded:");\r
                        Console.WriteLine("  {0}", Installation.ToString(installations));\r
                        if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
@@ -288,53 +268,10 @@ namespace AllGet
                                Environment.Exit(0);\r
                        }\r
                        \r
-                       NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations);\r
-                       tasks.Downloader = this.downloader;\r
-                       tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) {\r
-                               char result = '\u0000';\r
-                               if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
-                                       result = AllGet.Util.Query(e.Message + " [y/R/n]?", "yrn", 'r');\r
-                               } else if (e.SelectionFlag == (NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) {\r
-                                       result = AllGet.Util.Query(e.Message + " [R/n]?", "rn", 'r');\r
-                               } else if (e.SelectionFlag == NaGetTaskQueryResult.CONTINUE) {\r
-                                       result = AllGet.Util.Query(e.Message + " [Y]?", "y", 'y');\r
-                               } else {\r
-                                       result = AllGet.Util.Query(e.Message + " [Y/n]?", "yn", 'y');\r
-                               }\r
-                               \r
-                               switch (result) {\r
-                                       case 'y':\r
-                                               return NaGetTaskQueryResult.CONTINUE;\r
-                                       case 'n':\r
-                                               return NaGetTaskQueryResult.CANCEL;\r
-                                       case 'r':\r
-                                               return NaGetTaskQueryResult.RETRY;\r
-                                       default:\r
-                                               return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
-                               }\r
-                       };\r
-                       tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
-                               switch (e.Type) {\r
-//                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
-//                                             break;\r
-                                       case NaGetTaskSetEventType.COMPLETED:\r
-                                               Console.WriteLine("Done.");\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.STARTED_TASKSET:\r
-                                               Console.Write("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
-                                               Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.INFO:\r
-                                               Console.WriteLine("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.ERROR:\r
-                                       case NaGetTaskSetEventType.WARNING:\r
-                                               Console.WriteLine("  [Error] " + e.TaskMessage);\r
-                                               break;\r
-                               }\r
-                       };\r
+                       NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListMan, installations);\r
+                       tasks.TaskEventRaised += TaskSetEventHandlers.OnTaskSetEvent;\r
+                       tasks.SubTaskEventRaised += TaskSetEventHandlers.OnDownloadSubTaskEvent;\r
+                       tasks.TaskQueryRaised += TaskSetEventHandlers.OnTaskQueryEvent;\r
                        \r
                        tasks.Run();\r
                }\r
@@ -350,16 +287,14 @@ namespace AllGet
                        PackageList<InstalledPackage> installedPkgList = new PackageList<InstalledPackage>();\r
                        installedPkgList.AddPackages(pkgListMan.GetAllInstalledPackages());\r
                        \r
-                       Uninstallation[] uninstallations = new Uninstallation[packagenames.Length];\r
+                       InstalledPackage[] insPkgs = new InstalledPackage[packagenames.Length];\r
                        for (int i = 0; i < packagenames.Length; i++) {\r
-                               InstalledPackage pkg = installedPkgList.GetPackageForName(packagenames[i]);\r
+                               insPkgs[i] = installedPkgList.GetPackageForName(packagenames[i]);\r
                                \r
-                               if (pkg == null) {\r
+                               if (insPkgs[i] == null) {\r
                                        Console.WriteLine("E: could not found package " + packagenames[i]);\r
                                        Environment.Exit(1);\r
                                }\r
-                               \r
-                               uninstallations[i] = new Uninstallation(pkg);\r
                        }\r
                        \r
 //                     if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) {\r
@@ -367,29 +302,8 @@ namespace AllGet
 //                             Environment.Exit(0);\r
 //                     }\r
                        \r
-                       NaGet.SubCommands.NaGetUninstall tasks = new NaGet.SubCommands.NaGetUninstall(pkgListMan, uninstallations);\r
-                       tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { \r
-                               switch (e.Type) {\r
-//                                     case NaGetTaskSetEventType.COMPLETED_TASKSET\r
-//                                             break;\r
-                                       case NaGetTaskSetEventType.COMPLETED:\r
-                                               Console.WriteLine("Done.");\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.STARTED_TASKSET:\r
-                                               Console.Write("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
-                                               Console.WriteLine(" ... Done. [{0}%]", (int) e.TaskProgressPercent);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.INFO:\r
-                                               Console.WriteLine("  " + e.TaskMessage);\r
-                                               break;\r
-                                       case NaGetTaskSetEventType.ERROR:\r
-                                       case NaGetTaskSetEventType.WARNING:\r
-                                               Console.WriteLine("  [Error] " + e.TaskMessage);\r
-                                               break;\r
-                               }\r
-                       };\r
+                       NaGet.SubCommands.NaGetUninstall2 tasks = new NaGet.SubCommands.NaGetUninstall2(pkgListMan, insPkgs);\r
+                       tasks.TaskEventRaised += TaskSetEventHandlers.OnTaskSetEvent;\r
                        \r
                        tasks.Run();\r
                }\r
@@ -428,7 +342,7 @@ namespace AllGet
                        Console.WriteLine("\t{0} search|show pkg1 [pkg2 ...]", executeFileName);\r
                        Console.WriteLine("\t{0} cleancache [pkg ...]", executeFileName);\r
                        Console.WriteLine("\t{0} download pkg1 [pkg2 ...]", executeFileName);\r
-                       Console.WriteLine("\t{0} install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
+                       Console.WriteLine("\t{0} [--quiet] install|uninstall pkg1 [pkg2 ...]", executeFileName);\r
                        Console.WriteLine();\r
                        Console.WriteLine("{0} is a simple command line interface for downloading and "+\r
                                          "installing packages. The most frequently used commands are update "+\r
@@ -449,7 +363,7 @@ namespace AllGet
                \r
                public void FooBar()\r
                {\r
-                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) {\r
+                       foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) {\r
                                Console.WriteLine("{0} : {1}", pkg.Name, pkg.UninstallInfo.UninstallString);\r
                        }\r
                }\r
@@ -471,6 +385,7 @@ namespace AllGet
                        Console.WriteLine("誰か {0} をスーパー牛さんパワー化してくれ", executeFileName);\r
                }\r
                \r
+               [STAThread]\r
                public static void Main(string[] args)\r
                {\r
                        // アーカイブSYSTEM32をパスに足す\r
@@ -480,81 +395,113 @@ namespace AllGet
                        \r
                        if (args.Length == 0) {\r
                                mc.Help();\r
-                       } else if (args[0] == "update") {\r
-                               if (args.Length != 1) {\r
-                                       Console.WriteLine("E: The update command takes no arguments");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               mc.Update();\r
-                       } else if (args[0] == "localupdate") {\r
-                               if (args.Length != 1) {\r
-                                       Console.WriteLine("E: The update command takes no arguments");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               mc.LocalUpdate();\r
-                       } else if (args[0] == "search") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: You must give exactly one pattern");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               \r
-                               mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
-                       } else if (args[0] == "show") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: You must give exactly one pattern");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               \r
-                               for (int i = 1; i < args.Length; i++) {\r
-                                       mc.Show(args[i]);\r
-                               }\r
-                       } else if (args[0] == "download") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation download");\r
-                                       Environment.Exit(1);\r
-                               }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
                                \r
-                               mc.Download(packages);\r
-                       } else if (args[0] == "install") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation install");\r
+                               Environment.Exit(1);\r
+                       } else {\r
+                               try {\r
+                                       NaGet.ArgParser argParser = new NaGet.ArgParser();\r
+                                       argParser["quiet"] = false;\r
+                                       args = argParser.Parse(args);\r
+                                       mc.silent = (bool) argParser["quiet"];\r
+                               } catch (ApplicationException e) {\r
+                                       Console.WriteLine(e.Message);\r
                                        Environment.Exit(1);\r
                                }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.Install(packages);\r
-                       } else if (args[0] == "checkupgrade") {\r
-                               mc.CheckUpgrade();\r
-                       } else if (args[0] == "remove") {\r
-                               if (args.Length <= 1) {\r
-                                       Console.WriteLine("E: Invalid operation remove");\r
+                       }\r
+                       \r
+                       // 引数ごとに操作を決定\r
+                       switch (args[0])\r
+                       {\r
+                               case "update":\r
+                                       if (args.Length != 1) {\r
+                                               Console.WriteLine("E: The update command takes no arguments");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       mc.Update();\r
+                                       break;\r
+                               case "localupate":\r
+                                       if (args.Length != 1) {\r
+                                               Console.WriteLine("E: The update command takes no arguments");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       mc.LocalUpdate();\r
+                                       break;\r
+                               case "search":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: You must give exactly one pattern");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       \r
+                                       mc.Search(string.Join(" ", args, 1, args.Length - 1));\r
+                                       break;\r
+                               case "show":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: You must give exactly one pattern");\r
+                                               Environment.Exit(1);\r
+                                       }\r
+                                       \r
+                                       for (int i = 1; i < args.Length; i++) {\r
+                                               mc.Show(args[i]);\r
+                                       }\r
+                                       break;\r
+                               case "download":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation download");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Download(packages);\r
+                                       }\r
+                                       break;\r
+                               case "install":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation install");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Install(packages);\r
+                                       }\r
+                                       break;\r
+                               case "checkupgrade":\r
+                                       mc.CheckUpgrade();\r
+                                       break;\r
+                               case "remove":\r
+                                       if (args.Length <= 1) {\r
+                                               Console.WriteLine("E: Invalid operation remove");\r
+                                               Environment.Exit(1);\r
+                                       } else {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.Remove(packages);\r
+                                       }\r
+                                       break;\r
+                               case "cleancache":\r
+                                       {\r
+                                               string[] packages = new string[args.Length - 1];\r
+                                               Array.Copy(args, 1, packages, 0, packages.Length);\r
+                                               \r
+                                               mc.CleanCache(packages);\r
+                                       }\r
+                                       break;\r
+                               case "foobar":\r
+                                       mc.FooBar();\r
+                                       break;\r
+                               case "hoge":\r
+                                       mc.Hoge();\r
+                                       break;\r
+                               case "moo":\r
+                                       mc.Moo();\r
+                                       break;\r
+                               default:\r
+                                       mc.Help();\r
+                                       \r
                                        Environment.Exit(1);\r
-                               }\r
-                               \r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.Remove(packages);\r
-                       } else if (args[0] == "cleancache") {\r
-                               string[] packages = new string[args.Length - 1];\r
-                               Array.Copy(args, 1, packages, 0, packages.Length);\r
-                               \r
-                               mc.CleanCache(packages);\r
-                       } else if (args[0] == "foobar") {\r
-                               mc.FooBar();\r
-                       } else if (args[0] == "hoge") {\r
-                               mc.Hoge();\r
-                       } else if (args[0] == "moo") {\r
-                               mc.Moo();\r
-                       } else {\r
-                               mc.Help();\r
-                               \r
-                               Environment.Exit(1);\r
+                                       break;\r
                        }\r
                }\r
        }\r