Пример #1
0
        /// <summary>
        /// Returns whether the given constraint matches the desired version
        /// for the mod we're processing.
        /// </summary>
        private static bool ConstraintPasses(string op, ModuleVersion version, ModuleVersion desiredVersion)
        {
            switch (op)
            {
            case "":
            case "=":
                return(version.IsEqualTo(desiredVersion));

            case "<":
                return(version.IsLessThan(desiredVersion));

            case ">":
                return(version.IsGreaterThan(desiredVersion));

            case "<=":
                return(version.CompareTo(desiredVersion) <= 0);

            case ">=":
                return(version.CompareTo(desiredVersion) >= 0);

            default:
                throw new Kraken(
                          string.Format("Unknown x_netkan_override comparator: {0}", op));
            }
        }
Пример #2
0
        public int RunCommand(object rawOptions)
        {
            var options = (CompareOptions)rawOptions;

            if (options.Left != null && options.Right != null)
            {
                var leftVersion  = new ModuleVersion(options.Left);
                var rightVersion = new ModuleVersion(options.Right);

                int compareResult = leftVersion.CompareTo(rightVersion);

                if (options.machine_readable)
                {
                    user.RaiseMessage(compareResult.ToString());
                }
                else if (compareResult == 0)
                {
                    user.RaiseMessage(
                        "\"{0}\" and \"{1}\" are the same versions.", leftVersion, rightVersion);
                }
                else if (compareResult < 0)
                {
                    user.RaiseMessage(
                        "\"{0}\" is lower than \"{1}\".", leftVersion, rightVersion);
                }
                else if (compareResult > 0)
                {
                    user.RaiseMessage(
                        "\"{0}\" is higher than \"{1}\".", leftVersion, rightVersion);
                }
                else
                {
                    user.RaiseMessage(
                        "Usage: ckan compare version1 version2");
                }
            }
            else
            {
                user.RaiseMessage(
                    "Usage: ckan compare version1 version2");
                return(Exit.BADOPT);
            }

            return(Exit.OK);
        }