<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Click on The Edge Cases</title>
    <link>https://www.kylestratis.com/tags/click/</link>
    <description>Recent content in Click on The Edge Cases</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>© 2025</copyright>
    <lastBuildDate>Fri, 18 Sep 2026 22:38:55 -0400</lastBuildDate>
    <atom:link href="https://www.kylestratis.com/tags/click/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Passing Arguments from Main Commands to Subcommands in Click</title>
      <link>https://www.kylestratis.com/notes/passing-arguments-from-main-commands-to-subcommands-in-click/</link>
      <pubDate>Wed, 05 Apr 2023 18:17:37 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/passing-arguments-from-main-commands-to-subcommands-in-click/</guid>
      <description>&lt;p&gt;If you have command groups in your CLI application so that you have subcommands, you can pass arguments from the group down to the subcommands with the context object. Here&amp;rsquo;s the pattern:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.group&lt;/span&gt;()  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.argument&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;arg1&amp;#34;&lt;/span&gt;, type&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;click&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;File(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;r&amp;#34;&lt;/span&gt;))  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.option&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;--option1&amp;#34;&lt;/span&gt;, default&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;test&amp;#34;&lt;/span&gt;)  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.pass_context&lt;/span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;cli&lt;/span&gt;(ctx, arg1, option: str):  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ctx&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;ensure_object(dict)  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ctx&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;obj[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;arg1&amp;#34;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; arg1  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ctx&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;obj[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;option1&amp;#34;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; option1  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.command&lt;/span&gt;()  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.argument&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;subcommand_arg&amp;#34;&lt;/span&gt;, type&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;str)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@click.pass_context&lt;/span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;trigger_training_job&lt;/span&gt;(ctx, subcommand_arg):  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    arg1_from_group &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; ctx&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;obj[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;arg1&amp;#34;&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; __name__ &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    cli(obj&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{})&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;source&#34;&gt;Source&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://click.palletsprojects.com/en/8.1.x/complex/#contexts&#34;&gt;Click documentation&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using Entry Points in Poetry</title>
      <link>https://www.kylestratis.com/notes/using-entry-points-in-poetry/</link>
      <pubDate>Wed, 27 Apr 2022 00:59:17 +0000</pubDate>
      <guid>https://www.kylestratis.com/notes/using-entry-points-in-poetry/</guid>
      <description>&lt;p&gt;same: &lt;a href=&#34;https://www.kylestratis.com/notes/using-poetry-to-change-python-versions-and-create-new-virtual-environment/&#34;&gt;Using Poetry to Change Python Versions and Create New Virtual Environment&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;using-entry-points-in-poetry&#34;&gt;Using Entry Points in Poetry&lt;/h2&gt;&#xA;&lt;p&gt;If you need to use &lt;a href=&#34;https://stackoverflow.com/questions/774824/explain-python-entry-points&#34;&gt;entry points&lt;/a&gt; in a Poetry project, you can use a feature in &lt;code&gt;pyproject.toml&lt;/code&gt; for the same behavior as in setuptools. This feature is the heading &lt;code&gt;[tool.poetry.scripts]&lt;/code&gt;. Under this, you create the linkage between a command and a function in your script in the form of &lt;code&gt;cmd = &amp;quot;package.module.path:function&amp;quot;&lt;/code&gt;, giving the fully qualified location of the function using the same dot notation as you would with an &lt;code&gt;import&lt;/code&gt; statement.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
