Example #1
0
        //private static Constants.ResourceType? listType;
        static int Main(string[] args)
        {
            Parser parser = new Parser(settings =>
            {
                settings.CaseSensitive = false;
                // settings.IgnoreUnknownArguments = false;
            });
            PrintTable table = new PrintTable {
                { Constants.HeaderStringType, 6 },
                { Constants.HeaderStringNameOfResource, 21 },
                { Constants.HeaderStringVersion, 16 },
                { Constants.HeaderStringFileSize, 11 },
            };

            if (args.ToList().Count == 0)
            {
                Logger.logError($"{Constants.APPLICATION_ALIAS} must be called with an action name. Available actions:");
                GetOptions.GetAllOptions();
                return(0);
            }

            return(CommandLine.Parser.Default.ParseArguments <InitOptions, AddOptions, ListOptions, AvailableOptions,
                                                              DependencyOption, PublishOptions, RemoveOptions>(args.ToList())
                   .MapResult(
                       (InitOptions opts) => InitOptions.initDirectories(),
                       (AddOptions opts) => AddOptions.AddPackage(args.ToList()),
                       (ListOptions opts) => ListOptions.ListResources(opts.resourceType, args.ToList()),
                       (AvailableOptions opts) => AvailableOptions.Available(),
                       (DependencyOption opts) => DependencyOption.ListAllDependencies(args.ToList()),
                       (PublishOptions opts) => PublishOptions.Publish(args.ToList()),
                       (RemoveOptions opts) => RemoveOptions.RemovePackage(args.ToList()),
                       errs => 1));
        }
Example #2
0
        public static void remove(ResourceIdentifier resourceDescription)
        {
            try
            {
                string resourceName = resourceDescription.resourceName;
                // Console.WriteLine(resourceName);
                ResourceType resourceType = resourceDescription.resourceType;
                // Console.WriteLine(resourceType);
                InitOptions.initDirectories();

                Logger.logLine($"Removing {resourceType.ToString().ToLower()} resource \"{resourceName}\"");
                if (!ResourceTypes.resourceFileExists(resourceType, resourceName))
                {
                    Logger.logError($"{resourceType} resource \"{resourceName}\" does not exist");
                    return;
                }

                if (resourceDescription.version != null)
                {
                    if (ResourceTypes.resourceVersionFileExists(resourceType, resourceName))
                    {
                        string localVersion = ResourceTypes.getResourceVersion(resourceType, resourceName);
                        if (localVersion != resourceDescription.version)
                        {
                            bool removeAnyways = Logger.askYesOrNo($"Present version is {localVersion}, not {resourceDescription.version}. Remove anyways?");
                            if (!removeAnyways)
                            {
                                Logger.logLine("Aborting resource removal.");
                                return;
                            }
                        }
                    }
                    else
                    {
                        bool removeAnyways = Logger.askYesOrNo($"Local file {resourceName} has unknown version. Remove anyways?");
                        if (!removeAnyways)
                        {
                            Logger.logLine("Aborting resource removal.");
                            return;
                        }
                    }
                }

                ResourceTypes.removeResourceFilesIfPresent(resourceType, resourceName);
                Logger.logLine("Resource removed");
            }
            catch (Exception ex)
            {
                Logger.logError($"File System Error: " + ex.Message);
            }
        }