`generate action` ignores `--url` and `--http`: the route always comes from the action name

オープン 初心者向け
#476 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
cli

調査の方向性

Issueでは、generate action オプションの宣言と #call による引き渡しに加え、ジェネレーターでの route_url と route_http の処理が示されています。これらのエントリーポイントを読み、解析されたオプション名がどのようにジェネレーターに渡るかを確認してください。ドキュメントに記載された --url と --http オプションによって、config/routes.rb に期待される route が生成されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

hanami generate action --help documents --url and --http, with this example:

hanami generate action sessions.new --url=/login
# => get "/login", to: "sessions.new"

With hanami-cli 3.0.0 both options are accepted without error and have no effect. The route written to config/routes.rb is derived from the action name alone:

$ bundle exec hanami generate action sessions.probe --url=/login
Created app/actions/sessions/probe.rb
Created app/views/sessions/probe.rb
Created app/templates/sessions/probe.html.erb
Created spec/actions/sessions/probe_spec.rb

# config/routes.rb
get "/sessions/probe", to: "sessions.probe"

--http is ignored the same way:

$ bundle exec hanami generate action posts.create --http=delete
# config/routes.rb
post "/posts", to: "posts.create"

Expected: get "/login", to: "sessions.probe" and delete "/posts", to: "posts.create", as documented.

Where it seems to come from

The command declares the options with an alias:

option :url, as: :url_path, required: false, type: :string, desc: "Action URL path"
option :http, as: :http_method, required: false, type: :string, desc: "Action HTTP method"

and #call takes url_path: nil, http_method: nil, **opts, which it forwards to the generator, where route_url / route_http do honour them.

As far as I can tell, as: is not something dry-cli knows about. In dry-cli 1.4.1, Dry::CLI::Option#initialize(name, options = {}) stores the extra keys without reading :as, and the parser assigns parsed values by option.name.to_sym (lib/dry/cli/parser.rb, parsed_options[option.name.to_sym] = value). So --url=/login arrives in #call as url: "/login" inside **opts, url_path stays nil, and the generator falls back to the name-derived route. Same for --http / http_method.

The option declarations are unchanged on main, and I could not find :as handling in dry-cli's main either, so I believe this is still present after the Dry CLI 2.0 move (read only, not executed).

Environment: hanami-cli 3.0.0, hanami 3.0.1, dry-cli 1.4.1, Ruby 3.4.6, macOS.

主要言語
Ruby
スター
33
フォーク
57
平均マージ
1日 6時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hanami/hanami-cli のほかの issue

hanami/hanami-cli の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。