개요
GitHub Copilot CLI를 사용하여 프로그래밍 방식으로 Copilot 프롬프트를 실행할 수 있습니다. 이 작업을 수행하는 두 가지 주요 방법이 있습니다.
- 터미널에서 직접 Copilot CLI 프롬프트를 실행합니다.
- Copilot CLI를 활용하는 스크립트 또는 자동화를 작성합니다.
이 가이드에서는 각 옵션에 대한 간단한 사용 사례를 안내합니다.
명령줄에서 프롬프트 실행
대화형 세션을 시작하지 않고 Copilot CLI 프롬프트를 전달하려면 플래그를 -p 사용합니다.
copilot -p "Summarize what this file does: ./README.md"
copilot -p "Summarize what this file does: ./README.md"
대화형 세션에 입력할 프롬프트는 다음과 함께 -p작동합니다.
스크립트에서 Copilot CLI 사용
프로그래밍 모드의 진정한 힘은 AI 기반 작업을 자동화하기 위한 스크립트 작성에서 비롯됩니다. 스크립트 내에서 프롬프트를 생성하거나 프롬프트의 일부를 동적 콘텐츠로 바꾼 다음 출력을 캡처하거나 스크립트의 다른 부분에 전달할 수 있습니다.
현재 디렉터리에서 10MB보다 큰 모든 파일을 찾고 Copilot CLI를 사용하여 각 파일에 대한 간략한 설명을 생성한 다음 요약 보고서를 이메일로 전송하는 스크립트를 만들어 보겠습니다.
-
리포지토리에서 호출
find_large_files.sh된 새 파일을 만들고 다음 콘텐츠를 추가합니다.Bash #!/bin/bash # Find files over 10 MB, use Copilot CLI to describe them, and email a summary EMAIL_TO="user@example.com" SUBJECT="Large file found" BODY="" while IFS= read -r -d '' file; do size=$(du -h "$file" | cut -f1) description=$(copilot -p "Describe this file briefly: $file" -s 2>/dev/null) BODY+="File: $file"$'\n'"Size: $size"$'\n'"Description: $description"$'\n\n' done < <(find . -type f -size +10M -print0) if [ -z "$BODY" ]; then echo "No files over 10MB found." exit 0 fi echo -e "To: $EMAIL_TO\nSubject: $SUBJECT\n\n$BODY" | sendmail "$EMAIL_TO" echo "Email sent to $EMAIL_TO with large file details."#!/bin/bash # Find files over 10 MB, use Copilot CLI to describe them, and email a summary EMAIL_TO="user@example.com" SUBJECT="Large file found" BODY="" while IFS= read -r -d '' file; do size=$(du -h "$file" | cut -f1) description=$(copilot -p "Describe this file briefly: $file" -s 2>/dev/null) BODY+="File: $file"$'\n'"Size: $size"$'\n'"Description: $description"$'\n\n' done < <(find . -type f -size +10M -print0) if [ -z "$BODY" ]; then echo "No files over 10MB found." exit 0 fi echo -e "To: $EMAIL_TO\nSubject: $SUBJECT\n\n$BODY" | sendmail "$EMAIL_TO" echo "Email sent to $EMAIL_TO with large file details." -
스크립트를 실행 가능하게 만듭니다.
Shell chmod +x find_large_files.sh
chmod +x find_large_files.sh -
스크립트를 실행합니다.
Shell ./find_large_files.sh
./find_large_files.sh
이 스크립트는 Copilot CLI를 활용하여 검색하는 파일에 대한 설명을 생성하므로 큰 파일의 내용을 열지 않고도 빠르게 이해할 수 있습니다.
디렉터리에 추가되는 새 파일과 같은 이벤트에 대한 응답으로 또는 cron 작업 또는 CI/CD 파이프라인을 사용하여 일정에 따라 이러한 스크립트를 자동으로 트리거할 수도 있습니다.
추가 읽기
-
[AUTOTITLE](/copilot/how-tos/copilot-cli/automate-copilot-cli/run-cli-programmatically) -
[AUTOTITLE](/copilot/how-tos/copilot-cli/automate-copilot-cli/automate-with-actions) -
[AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-programmatic-reference)