{"id":13466125,"url":"https://github.com/ardacetinkaya/Blazor.Console","last_synced_at":"2025-03-25T21:31:19.468Z","repository":{"id":41118099,"uuid":"221755474","full_name":"ardacetinkaya/Blazor.Console","owner":"ardacetinkaya","description":"A simple component to mock CLI for ASP.NET Core Blazor applications to execute some custom commands for an application","archived":false,"fork":false,"pushed_at":"2020-11-24T17:46:14.000Z","size":1562,"stargazers_count":68,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T19:17:01.314Z","etag":null,"topics":["asp-net-core","aspnetcore","blazor","blazor-component","blazor-server","commandline","dotnet-core","dotnetcore"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ardacetinkaya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-14T17:49:04.000Z","updated_at":"2024-09-27T16:58:14.000Z","dependencies_parsed_at":"2022-08-27T04:12:01.886Z","dependency_job_id":null,"html_url":"https://github.com/ardacetinkaya/Blazor.Console","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ardacetinkaya%2FBlazor.Console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ardacetinkaya%2FBlazor.Console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ardacetinkaya%2FBlazor.Console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ardacetinkaya%2FBlazor.Console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ardacetinkaya","download_url":"https://codeload.github.com/ardacetinkaya/Blazor.Console/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245547318,"owners_count":20633345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","aspnetcore","blazor","blazor-component","blazor-server","commandline","dotnet-core","dotnetcore"],"created_at":"2024-07-31T15:00:39.500Z","updated_at":"2025-03-25T21:31:19.135Z","avatar_url":"https://github.com/ardacetinkaya.png","language":"C#","funding_links":[],"categories":["Sample Projects"],"sub_categories":["Others"],"readme":"# Blazor.CommandLine (a.k.a Blazor.Console)\n\n[![Actions Status](https://github.com/ardacetinkaya/Blazor.Console/workflows/Build/badge.svg)](https://github.com/ardacetinkaya/Blazor.Console/actions)\n[![NuGet version (Blzr.Components.CommandLine)](https://img.shields.io/nuget/v/Blzr.Components.CommandLine.svg)](https://www.nuget.org/packages/Blzr.Components.CommandLine/)\n\nDevelopment: ![Build](https://github.com/ardacetinkaya/Blazor.Console/workflows/Build/badge.svg?branch=development)\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/ardacetinkaya/Blazor.Console/blob/master/screenshots/1.png\" /\u003e\n\u003c/p\u003e\n\n### What and why... ###\n\nThis is a simple console component for ASP.NET Core 3.0 Blazor Server application model. The motivation behind this simple component is to provide simple command-line interface to manage some Web API. With this component it is easy to execute some business related commands.* \n\nReal life scenario examples;\n- Clear response cache\n- Export log files\n- Change run-time settings\n- Monitor application resources\n\nThis Blazor component is based on ```System.CommandLine``` API and reflects standart command-line features to be more reliable.\n\n### Usage ###\n\nCheck Demo project(BlazorConsoleDemo.csproj) for usage;\n\nAdd following extensions to services and application within Startup.cs\n\n```cs\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddCommandLine();\n}\n\npublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)\n{\n    app.UseCommandLine(env.WebRootPath);\n}\n```\n\nAdd \u003cBlazorCommandLine\u003e tag into needed view file(ex: Index.razor)\n\n```html\n@page \"/\"\n@using Blazor.CommandLine\n@using Blazor.Components.CommandLine\n@using Blazor.Components.CommandLine.Console\n\n\u003ch1\u003eHello, world!\u003c/h1\u003e\n\n\u003cBlazorCommandLine @ref=\"console\" Name=\"Some Demo App v1.0.0\"/\u003e\n```\n\nAnd to have fancy UI add CSS to host file, _HOST.cshtml\n\n```html\n\u003clink href=\"Blazor.CommandLine/styles.css\" rel=\"stylesheet\" /\u003e\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/ardacetinkaya/Blazor.Console/blob/master/screenshots/2.png\" /\u003e\n\u003c/p\u003e\n\n### Commands ###\n\nAdding commands to Blazor.CommandLine is not complicated. First create a command class, implement it with ```BaseCommand``` . Then add the command(s) to the BlazorCommandLine's Commands as below;\n\nWithin custom command's constructor it is easy to add options to the command. Also command arguments can be enabled for the command as ```System.CommandLine```\n\nTo implement the command's main execution just override Execute() or ExecuteAsync() method. \n\n```cshtml\n@page \"/\"\n@using Blazor.CommandLine\n@using Blazor.Components.CommandLine\n@using Blazor.Components.CommandLine.Console\n\n@inject IRunningCommand RunningCommand\n\n\u003ch1\u003eHello, world!\u003c/h1\u003e\n\n\u003cBlazorCommandLine @ref=\"console\" /\u003e\n\n@code\n{\n    BlazorCommandLine console;\n\n    protected override Task OnAfterRenderAsync(bool firstRender)\n    {\n        console.Commands.Add(new CommandExample(\"simple\",\"Description of command\"));\n        console.Commands.Add(new LongCommand(\"lng\",\"Description of long-running command\"));\n\n        return base.OnAfterRenderAsync(firstRender);\n    }\n\n    public class CommandExample : BaseCommand\n    {\n        public CommandExample(string name,string description):base(name,description)\n        {\n            base.AddOption(\"-t\",\"Description of option -t\");\n            base.AddOption(\"-ar\",\"Description of option -ar\");\n\n            base.UseArguments($\"Some extra arguments for {name}\");\n        \n        }\n\n        public override bool Execute(DefaultStreamWriter console,string option1,string option2,string option3,string option4,List\u003cstring\u003e arguments)\n        {\n            console.Write(\"This is output of a simple command\");\n            return true;\n        }\n    }\n\n    public class LongCommand : BaseCommand\n    {\n        public LongCommand(string name, string description):base(name,description,true)\n        {\n            \n        }\n\n        public override async Task\u003cbool\u003e ExecuteAsync(DefaultStreamWriter console, string option1,string option2,string option3,string optionArgument4,List\u003cstring\u003e arguments)\n        {\n            var i = 0;\n\n            while (i \u003c 10)\n            {\n                await Task.Delay(550);\n                i++;\n            }\n            \n            console.Write(\"This was a long running command\");\n            return true;\n        }\n    }\n}\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/ardacetinkaya/Blazor.Console/blob/master/screenshots/3.png\" /\u003e\n\u003c/p\u003e\n\n### References ###\n- Some commands might be long running tasks, Blazor.CommandLine use some features of a great component for this kind of requirement. Please also check  https://github.com/h3x4d3c1m4l/Blazor.LoadingIndicator if you need a loading indicator for a Blazor app.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fardacetinkaya%2FBlazor.Console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fardacetinkaya%2FBlazor.Console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fardacetinkaya%2FBlazor.Console/lists"}