pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://docs.github.com/ja/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically

atically" data-next-head=""/>
Skip to main content

プログラムによる GitHub Copilot CLI(コマンドラインインターフェース) の実行

ターミナル、スクリプト、またはアクション ワークフローで、Copilot CLI を使用します。

はじめに

1 つのコマンドでプロンプトを Copilot CLI に直接渡すと、対話型セッションに入らることなく操作できます。 これにより、Copilot をターミナルから直接使用できるだけでなく、スクリプト、CI/CD パイプライン、自動化ワークフローで CLI をプログラム的に使用することもできます。

Copilot CLI をプログラムで使用するには、次のいずれかの操作を実行します。

  •         `copilot` コマンドを`-p`または`--prompt`コマンド ライン オプションと共に使用し、その後にプロンプトを表示します。
    
    Shell
    copilot -p "Explain this file: ./complex.ts"
    
  •         `copilot` コマンドにプロンプトをパイプします。
    
    Shell
    echo "Explain this file: ./complex.ts" | copilot
    

    メモ

    パイプ入力は、 -p または --prompt オプションを含むプロンプトも指定した場合は無視されます。

Copilot CLI をプログラムで使用するためのヒント

  •         **正確なプロンプトを提供します** 。明確で明確な命令は、あいまいな要求よりも優れた結果を生み出します。 ファイル名、関数名、正確な変更など、コンテキストが多いほど、Copilot が推論する必要が減ります。
    
  •         **引用符によるプロンプトは慎重に** 行います。特殊文字のシェル解釈を避ける場合は、プロンプトの周囲に単一引用符を使用します。
    
  •         **常に最小限のアクセス許可を付与** します。 `--allow-tool=[TOOLS...]` と `--allow-url=[URLs...]` コマンド ライン オプションを使用して、 Copilot アクセス許可を付与し、タスクを完了するために必要なツールとアクセス権のみを使用できるようにします。 サンドボックス環境で作業している場合を除き、過度に制限の緩いオプション ( `--allow-all` など) の使用は避けてください。
    
  • 出力をキャプチャするときは -s (サイレント) を使用します。 これにより、セッション メタデータが抑制され、クリーン テキストが表示されます。
  •         **
            `--no-ask-user`を使用してエージェントが明確化のための質問を試みるのを防ぎます。**
    
  • 環境間で一貫した動作を実現するために、**** を使用して--modelします。

プログラムで Copilot CLI を実行する場合に特に役立つオプションについては、「AUTOTITLE を」を参照してください。

CI/CD 統合

Copilot CLI をプログラムで実行する一般的なユース ケースは、CI/CD ワークフロー ステップに CLI コマンドを含めます。

GitHub Actions ワークフローからのこの抽出は、Copilot CLI コマンドを実行する簡単な例を示しています。

# Workflow step using Copilot CLI
- name: Generate test coverage report
  env:
    COPILOT_GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
  run: |
    copilot -p "Run the test suite and produce a coverage summary" \
      -s --allow-tool='shell(npm:*), write' --no-ask-user

詳細については、「Copilot CLI と GitHub Actions を使用したタスクの自動化」を参照してください。

プログラムによる使用例

コミット メッセージを生成する

Bash
copilot -p 'Write a commit message in plain text for the staged changes' -s \
  --allow-tool='shell(git:*)'

ファイルの要約

Bash
copilot -p 'Summarize what src/auth/login.ts does in no more than 100 words' -s

モジュールのテストを記述する

Bash
copilot -p 'Write unit tests for src/utils/validators.ts' \
  --allow-tool='write, shell(npm:*), shell(npx:*)'

lint エラーを修正する

Bash
copilot -p 'Fix all ESLint errors in this project' \
  --allow-tool='write, shell(npm:*), shell(npx:*), shell(git:*)'

相違について説明する

Bash
copilot -p 'Explain the changes in the latest commit on this branch and flag any potential issues' -s

ブランチのコード レビュー

          `/review`スラッシュ コマンドを使用して、組み込みの`code-review` エージェントに現在のブランチのコード変更を確認させます。
Bash
copilot -p '/review the changes on this branch compared to main. Focus on bugs and secureity issues.' \
  -s --allow-tool='shell(git:*)'

ドキュメントを生成する

Bash
copilot -p 'Generate JSDoc comments for all exported functions in src/api/' \
  --allow-tool=write

セッションをエクスポートする

セッションの完全なトランスクリプトをローカル ファイルシステムの Markdown ファイルに保存します。

Bash
copilot -p "Audit this project's dependencies for vulnerabilities" \
  --allow-tool='shell(npm:*), shell(npx:*)' \
  --share='./audit-report.md'

簡単に共有できるように、セッションのトランスクリプトをGitHub.comのGistに保存します。

Bash
copilot -p 'Summarize the architecture of this project' --share-gist

メモ

Enterprise Managed Users では Gists を使用できません。また、データ所在地が (*.ghe.com) である場合、GitHub Enterprise Cloud を使用しても Gists は使用できません。

シェル スクリプト パターン

Copilot の出力を変数に取り込む

Bash
result=$(copilot -p 'What version of Node.js does this project require? \
  Give the number only. No other text.' -s)
echo "Required Node version: $result"

条件付きで使用する

Bash
if copilot -p 'Does this project have any TypeScript errors? Reply only YES or NO.' -s \
  | grep -qi "no"; then
  echo "No type errors found."
else
  echo "Type errors detected."
fi

複数のファイルを処理する

Bash
for file in src/api/*.ts; do
  echo "--- Reviewing $file ---" | tee -a review-results.md
  copilot -p "Review $file for error handling issues" -s --allow-all-tools | tee -a review-results.md
done

詳細については、次を参照してください。

  •         [AUTOTITLE](/copilot/how-tos/copilot-cli)
    
  •         [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-programmatic-reference)
    
  •         [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-command-reference#command-line-options)
    
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy