A terse summary of a directory (non-recursive).
This is a simple application experimenting with .NET Core 3, F#, and Argu. In fact, the idea for the functionality is based on a suggested exercise working with collections from Get Programming with F#.
From Argu.
USAGE: derse [--help] --directory <directory>
OPTIONS:
--directory <directory>
Directory to create summary
--help display this list of options.
Prints the following information to the console.
- Directory
- Total File Size (not necessarily size on disk)
- Average File Size
- File Count
- File Extensions
The summary is not recursive at the moment. It is only prints one directory deep.
In addition, error checking to see if the --directory
passed in exists and is truly a directory needs to be added. It is assumed that at least 1 directory and at least 1 file within a directory exists. May need to use other functions from the Seq
module such as Seq.choose
in order to work with Option types.
Download and install .NET Core 3. For this example, I am utilizing the following versions of software. Note that Argu
is added within Project Creation and Dependencies.
macOS version:
10.14.6
dotnet core version:
3.0.100-preview9-014004
Argu version:
Project 'derse' has the following package references
[netcoreapp3.0]:
Top-level Package Requested Resolved
> Argu 5.5.0 5.5.0
> FSharp.Core 4.7.0 4.7.0
This is produced from versions.sh
.
Create a console application.
dotnet new console -lang F#
Add Argu as a dependency.
dotnet add package Argu --version=5.5.0
Write the code.
Build and then run to test.
dotnet build
Then to test.
dotnet run -- --directory "/some/random/dir"
Now because of [.NET Core 3], we can publish as a single exe.
dotnet publish -r osx-x64 -c Release /p:PublishSingleFile=true
To test.
bin/Release/netcoreapp3.0/osx-x64/publish/derse --help
How large is the file?
du -sh bin/Release/netcoreapp3.0/osx-x64/publish/derse
It is coming in at 80M
. Yikes!
Reduce the size of the exe. Edit the derse.fsproj
file. Add the tags <PublishTrimmed>
, <PublishReadyToRun>
, <PublishSingleFile>
, and <RuntimeIdentifier>
.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Compile Include="Arguments.fs" />
<Compile Include="Dir.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Argu" Version="5.5.0" />
</ItemGroup>
</Project>
Test again.
bin/Release/netcoreapp3.0/osx-x64/publish/derse --help
Check the size again.
du -sh bin/Release/netcoreapp3.0/osx-x64/publish/derse
Better - at 61MB
.
Can Warp reduce the size of the exe?
First, add a .NET Core global tool.
dotnet tool install -g dotnet-warp
Under construction. 🚧
Figure out use of paket while still utilizing .NET Core SDK
.
Push with a git tag and then have DevOps build and cut a release on Github. Add instructions using curl
to install to the README.