<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://wiki.soulruins.ru/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>Philip Wiki - docs:blog:2024:01</title>
        <description>Персональный wiki-сайт</description>
        <link>https://wiki.soulruins.ru/</link>
        <lastBuildDate>Fri, 17 Apr 2026 16:31:07 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://wiki.soulruins.ru/_media/wiki/dokuwiki.svg</url>
            <title>Philip Wiki</title>
            <link>https://wiki.soulruins.ru/</link>
        </image>
        <item>
            <title>Динамические набор параметров и небольшой лайфхак</title>
            <link>https://wiki.soulruins.ru/docs/blog/2024/01/cheat_powershell?rev=1723880553&amp;do=diff</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;dinamicheskie_nabor_parametrov_i_nebolshoj_lajfxak&quot;&gt;Динамические набор параметров и небольшой лайфхак&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Хотите немного магии? Она есть у меня! &lt;img src=&quot;https://wiki.soulruins.ru/lib/images/smileys/smile.svg&quot; class=&quot;icon smiley&quot; alt=&quot;:-)&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
В очередной раз решив немного поковырять настройки своего терминала, вспомнил про замечательный ресурс &lt;a href=&quot;https://cheat.sh&quot; class=&quot;urlextern&quot; target=&quot;_blank&quot; title=&quot;https://cheat.sh&quot; rel=&quot;ugc nofollow noopener&quot;&gt;https://cheat.sh&lt;/a&gt;. А ещё я вспомнил, что хотел прикрутить его к своему терминалу, чтобы быстро и удобно получать справку по командам и утилитам (например &lt;code&gt;7z&lt;/code&gt;, &lt;code&gt;yt-dlp&lt;/code&gt; …). А что может быть удобнее автоподстановки доступных на cheat.sh команд?
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://wiki.soulruins.ru/_media/docs/blog/2024/01/pasted/20240119-095701.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;level1&quot;&gt;
&lt;div id=&quot;plugin__gallery_05d6&quot; class=&quot;plugin-gallery align-full&quot;&gt;&lt;div class=&quot;gallery-page&quot; id=&quot;gallery__05d6_0&quot; style=&quot;grid-template-columns: repeat(auto-fill, minmax(600px, 1fr))&quot;&gt;&lt;figure class=&quot;gallery-image&quot;&gt;&lt;a href=&quot;https://wiki.soulruins.ru/_detail/docs/blog/2024/01/pasted/20240119-111530.png?id=docs%3Ablog%3A2024%3A01%3Acheat_powershell&quot; title=&quot;20240119-111530&quot; data-caption=&quot;&amp;lt;b&amp;gt;20240119-111530&amp;lt;/b&amp;gt;&quot; class=&quot;lightbox JSnocheck&quot; rel=&quot;lightbox[gal-ac3827d24961a87e4a7379b90662]&quot; data-url=&quot;https://wiki.soulruins.ru/_media/docs/blog/2024/01/pasted/20240119-111530.png&quot;&gt;&lt;img width=&quot;908&quot; height=&quot;521&quot; src=&quot;https://wiki.soulruins.ru/_media/docs/blog/2024/01/pasted/20240119-111530.png?w=908&amp;amp;h=521&amp;amp;tok=eac50f&quot; alt=&quot;20240119-111530.png&quot; loading=&quot;lazy&quot; /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;
Итак. Всё что нужно – сделать функцию, в которой будет реализован механизм получения её параметров из внешнего источника. Собственно, решение я подсмотрел на &lt;a href=&quot;https://stackoverflow.com/a/68824687&quot; class=&quot;interwiki iw_so&quot; target=&quot;_blank&quot; title=&quot;https://stackoverflow.com/a/68824687&quot; rel=&quot;noopener&quot;&gt;stackoverflow&lt;/a&gt;, там развернули использование атрибута &lt;code&gt;ValidateScript&lt;/code&gt; и даже предложили как сделать прогнозирование.
&lt;/p&gt;

&lt;p&gt;
Сама функция:
&lt;/p&gt;
&lt;pre class=&quot;code powershell&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;Function&lt;/span&gt; cheat &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;coMULTI&quot;&gt;&amp;lt;# profile function #&amp;gt;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;CmdletBinding&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;param&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;Parameter&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Mandatory&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;ValidateScript&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;a target=&quot;_blank&quot; href=&quot;about:blank&quot;&gt;&lt;span class=&quot;kw6&quot;&gt;$_&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;curl cht.sh&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;:list&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
    ErrorMessage &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&#039;Please specify the name of the command in the query.&#039;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;ArgumentCompleter&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span class=&quot;kw3&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$cmd&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$param&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$wordToComplete&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;co1&quot;&gt;# This is the duplicated part of the code in the [ValidateScipt] attribute.&lt;/span&gt;
      &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;re3&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$validValues&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;curl cht.sh&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;:list&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;re0&quot;&gt;$validValues&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;-like&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;$wordToComplete*&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;re3&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$command&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;re3&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$question&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$question&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;re3&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$command&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$command&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&#039;/&#039;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$question&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
curl cht.sh&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$command&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Дополнительно добавил поддержку &lt;code&gt;question&lt;/code&gt;, т.к. &lt;code&gt;cheat.sh&lt;/code&gt; умеет вот такое &lt;pre class=&quot;code&quot;&gt;cheat powershell how+select+and+filter+object&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&quot;tags&quot;&gt;&lt;span&gt;
	&lt;a href=&quot;https://wiki.soulruins.ru/tags/powershell?do=showtag&amp;amp;tag=powershell&quot; class=&quot;wikilink1&quot; title=&quot;tags:powershell&quot; rel=&quot;tag&quot;&gt;powershell&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 17 Aug 2024 07:42:33 +0000</pubDate>
        </item>
    </channel>
</rss>
