New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: スキーマを利用した新コマンドシステム #479
Conversation
Codecov Report
@@ Coverage Diff @@
## main #479 +/- ##
==========================================
+ Coverage 71.28% 73.94% +2.66%
==========================================
Files 58 60 +2
Lines 3952 4352 +400
Branches 373 372 -1
==========================================
+ Hits 2817 3218 +401
- Misses 762 763 +1
+ Partials 373 371 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
76d7984
to
0f63050
Compare
0f63050
to
caa0164
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビュー前にデバックした際に気がついて、特に #479 などに記述がなかった箇所を書いておきます。
!help
にてサブコマンドに関する記述が消えてしまっていること- feat: userinfoコマンドの拡張案 #474 にて追加された
!userinfo me
が利用できなくなっていること (!userinfo me
ではUSER
型の値が期待されているが、me
(おそらく文字列の判定?) になってしまっている)
Edit(10:41):!userinfo me
って想定されていない?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
お疲れ様です
レビューに自信がないですがよろしくお願いします
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, approve
* feat: Add Schema * docs: Add docs and tidy up * fix: Add paramsOrder * fix: Improve SubCommand * fix: Fix error payload * fix: Add NEED_MORE_ARGS error * fix: Add type parameters * fix: Fix arg of ParsedSubCommand * fix: Improve parsed types * fix: Support params on Schema * refactor: Update CommandMessage * feat: Impl parseStrings * fix: Fix to check range * fix: Add makeError * fix: Weaken type bound * test: Add simple test case * fix: Fix some keys and test case * fix: Remove parsed key * test: Enforce test case * test: Enforce test cases * fix: Fix DIGITS and update output * feat: Add MESSAGE type * fix: Make subCommand and params required * fix: Weaken type bound * fix: Improve ParsedSchema * fix: Fix fallback type * fix: Fix type on single arg * fix: Fix type pattern match * feat: Add ParamBase * fix: Fix SubCommand definition * fix: Support variadic arguments * fix: Make subCommand optional * feat: Add SCHEMA * fix: Improve ParamsValues * fix: Fix registration * feat: Add parseStringsOrThrow * fix: Fix type bound * fix: Improve createMockMessage args * fix: Remove empty subCommand from output * fix: Weaken type of param * fix: Fix on no args but has sub command * fix: Fix to report error * test: Update command tests * fix: Guard on other commands * fix: Fix typing with Equal * feat: Improve with CommandRunner * fix: Remove redundant test * doc: Update CONTRIBUTING for newer method * fix: Fix not to throw error * fix: Fix parsing variadic params * fix: Fix decoupling * feat: Add more hibikiness * fix: Guard with checking editable
🎉 This PR is included in version 1.26.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
close #461.
Type of Change:
コードのリファクタ, システムの高度化, テストの修正
Details of implementation (実施内容)
各コマンドが引数のスキーマを定義すると, アダプタ側がそれを読み取ります. コマンドが送られてきたときに, 正しい形式の引数かどうかをスキーマを基に判別して引数の値を取り出します. スキーマの定義は
model/command-schema.ts
に定義しており, 概ね以下のような構成です.これにより
CommandMessage
の定義ならびに全てのコマンドの実装を改修し, テストもあわせて修正しています.Additional Information (追加情報)
この改修に伴い, コマンド実装側で引数の形式や範囲が正しいかどうかチェックする手間がなくなり, コマンド引数の型がより強固になります. その代わり, スキーマの書き方の支援がいまのところ少ない (TypeScript による読みにくいエラーしかない) ので「スキーマの書き方を学ぶ」実装コストが増えています.
コマンド実行の際にスキーマの定義に沿わない引数が渡された場合は, アダプタ側のパース処理の段階でエラーが発生して弾かれます. そのため, パース処理のエラーをユーザーに返信するようになっており, これまでのようなコマンドごとのユニークなエラーメッセージが見られなくなります.
また, コマンドのイベントとメッセージ作成のイベントを分割したため, コマンド側ではメッセージの削除に反応できなくなりました. これにより, 煩わしい
event !== 'CREATE'
の判定をすべて消しました.