Skip to content

0.4.0 - FilePath and DirectoryPath bind types

Compare
Choose a tag to compare
@xforever1313 xforever1313 released this 03 Apr 18:00
· 48 commits to master since this release

Downloads

Release Notes

FilePathArgumentAttribute and DirectoryPathArgumentAttribute

In this release, more types can be bounded to; specifically FilePath and DirectoryPath. This can be done with the FilePathArgument and DirectoryPathArgument respectively.

The main advantage of using these over a StringArgument is they contain a property called MustExist. For example, if you bind "c:\somewhere.txt" to a property binded to a FilePath, and it does not exist, the cake process will exit with an error. This way, you no longer need to check to see if a file or directory exists in your tasks, just have it setup in your config class.

An example, taken from our integration tests:

        public class FilePathBind
        {
            // ---------------- Fields ----------------

            internal const string RequiredArgName = "file_required";
            private const string requiredArgDescription = "A Required file";

            internal const string OptionalArgName = "file_optional";
            private const string optionalArgDescription = "An optional file";
            internal const string DefaultValue = "Hello";

            internal const string NullArgName = "file_nullarg";
            private const string nullArgDescription = "A file whose default value is null";
            internal const string NullDefaultValue = null;

            internal const string MustExistArgName = "file_mustexist";
            private const string mustExistArgDescription = "Must exist optional file";

            // ---------------- Properties ----------------

            [FilePathArgument(
                RequiredArgName,
                Description = requiredArgDescription,
                HasSecretValue = false,
                Required = true,
                MustExist = false
            )]
            public FilePath RequiredArg { get; set; }

            [FilePathArgument(
                OptionalArgName,
                Description = optionalArgDescription,
                HasSecretValue = false,
                DefaultValue = DefaultValue,
                Required = false,
                MustExist = false
            )]
            public FilePath OptionalArg { get; set; }

            [FilePathArgument(
                NullArgName,
                Description = nullArgDescription,
                HasSecretValue = false,
                DefaultValue = NullDefaultValue,
                Required = false,
                MustExist = false
            )]
            public FilePath NullDefaultArg { get; set; }

            [FilePathArgument(
                MustExistArgName,
                Description = mustExistArgDescription,
                HasSecretValue = false,
                Required = true,
                MustExist = true
            )]
            public FilePath FileMustExistArg { get; set; }

            // ---------------- Functions ----------------

            public override string ToString()
            {
                return ArgumentBinder.ConfigToStringHelper( this );
            }
        }

Hidden Value Changes

If a property is set to have its value hidden, the DefaultValue, Min, and Max value(s) will not appear when printing out a description. As usual, the ToString helper function will also hide the hidden value.

If a property is set to not have its value hidden, then "Value Hidden: false" no longer appears in the Description string. The reason why is this just seemed to take up too much space in the print out, and didn't provide any useful information.

Other fixes

  • If a Default value is null, we will not NRE when calling a description or ToString helper.
  • If a value is null, we will not NRE when calling a description or a ToString helper.