ConsoleAsksFor 1.0.0-prerelease-20211003103006

This is a prerelease version of ConsoleAsksFor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package ConsoleAsksFor --version 1.0.0-prerelease-20211003103006                
NuGet\Install-Package ConsoleAsksFor -Version 1.0.0-prerelease-20211003103006                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConsoleAsksFor" Version="1.0.0-prerelease-20211003103006" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConsoleAsksFor --version 1.0.0-prerelease-20211003103006                
#r "nuget: ConsoleAsksFor, 1.0.0-prerelease-20211003103006"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ConsoleAsksFor as a Cake Addin
#addin nuget:?package=ConsoleAsksFor&version=1.0.0-prerelease-20211003103006&prerelease

// Install ConsoleAsksFor as a Cake Tool
#tool nuget:?package=ConsoleAsksFor&version=1.0.0-prerelease-20211003103006&prerelease                

ConsoleAsksFor

ConsoleAsksFor is library for asking for input in a console app easily.

Goal

The aim of ConsoleAsksFor removing hassle of retrieving input in a console app without manually having to parse or to retry when invalid.

Installation

You can download the latest release / pre-release NuGet packages from nuget:

Setup

Register Console with ConsoleAsksFor.Microsoft.DependencyInjection:

services.AddConsoleAsksFor();

Resolve a service which has dependency on IConsole of resolve service directly:

var console = serviceProvider.GetRequiredService<IConsole>();

Or create with factory:

ConsoleFactory.Create();

Start using

Some examples:

var isSure = await console.AskForBool("Are you sure?");
var age = await console.AskForInt("What is your age?", Between(0, 125));
var length = await console.AskForDecimal("What is your length (in meters)?", DecimalPrecision.Two, Between(0m, 2.5m));
var appointmentStart = await console.AskForDateTimeOffset("How late should we meet?", TimeZoneInfo.Local, AtLeast(DateTimeOffset.Now), defaultValue: DateTimeOffset.Now.AddHours(1));
var favoriteColor = await console.AskForEnum<ConsoleColor>("What is your favorite color?");
var preferredName = await console.AskForItem("Which name do you prefer?", new[] { "Jantje", "Pietje" });
var directory = await console.AskForExistingDirectory("Where to store file?", defaultValue: new DirectoryInfo(@"C:\Temp"));
var name = await console.AskForString("What is your name?");
var zipcode = await console.AskForString("What is your Dutch zipcode?", new Regex("^[1-9][0-9]{3}[A-Z]{2}$"), "Format: '5555AA' where first digit is not a 0");
var pw = await console.AskForPassword("What is the secret code?");

Demo

img

Features

  • Default values
  • History
    • ByQuestionTextAndType (default)
    • ByQuestionType
    • NotFiltered
  • Basic Intellisense
  • Colors
    • Visual feedback whether current answer is correct
    • Different colors for different line types
    • Customizable
  • Basic multithreading support:
    • During asking questions other output to Console is suspended
    • When multiple treads are asking questions, questions are queued

Supported types

ConsoleAsksFor

  • AskForBool
  • AskForByte
  • AskForSignedByte
  • AskForShort
  • AskForUnsignedShort
  • AskForInt
  • AskForUnsignedInt
  • AskForLong
  • AskForUnsignedLong
  • AskForDecimal
  • AskForDate
  • AskForDateTime
  • AskForDateTimeOffset
  • AskForDirectory
  • AskForExistingDirectory
  • AskForNewDirectory
  • AskForFileName
  • AskForExistingFileName
  • AskForNewFileName
  • AskForEnum<T>
  • AskForFlaggedEnum<T>
  • AskForItem<T>
  • AskForItems<T>
  • AskForString
  • AskForPassword

ConsoleAsksFor.NodaTime.ISO

  • AskForInstant
  • AskForLocalDate
  • AskForLocalDateTime
  • AskForLocalTime
  • AskForZonedDateTime
  • AskForAnnualDate
  • AskForYearMonth

Release notes

See the Releases page ConsoleAsksFor for release history.

Versioning

ConsoleAsksFor follows Semantic Versioning 2.0.0 for the releases published to nuget.org.

Credits

Other

Another reason to make ConsoleAsksFor is because I have never worked with github and never created public nuget package. So this is a little brain exercise I guess 😃.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ConsoleAsksFor:

Package Downloads
ConsoleAsksFor.NodaTime.ISO

NodaTime (ISO) integration for ConsoleAsksFor.

ConsoleAsksFor.Microsoft.DependencyInjection

Microsoft DependencyInjection integration for ConsoleAsksFor.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.1.0 105 11/15/2024
4.1.0-prerelease-2024111511... 76 11/15/2024
4.0.0 113 11/3/2024
3.1.0 548 12/27/2022
3.0.0 712 5/10/2022
2.0.0 442 12/31/2021
2.0.0-prerelease-2021123111... 220 12/31/2021
1.0.0 575 10/4/2021
1.0.0-prerelease-2021100310... 381 10/3/2021