Skip to main content
Skip to content

프로그래밍 방식으로 실행 GitHub Copilot CLI

Copilot CLI을(를) 터미널, 스크립트 또는 작업 워크플로에서 사용합니다.

소개

대화형 세션을 입력하지 않고 단일 명령으로 직접 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)을 사용하지 마세요. 자세한 내용은 클라우드 및 로컬 샌드박스에 대하여 GitHub Copilot을(를) 참조하세요.
  • 출력을 캡처할 때 (자동)를 사용합니다-s. 이렇게 하면 세션 메타데이터가 표시되지 않으므로 텍스트가 정리됩니다.
  • 사용 --no-ask-user 에이전트가 명확한 질문을 하지 못하도록 합니다.
  • 환경 전체에서 일관된 동작을 위해 명시적으로 ****--model.

프로그래밍 방식으로 실행할 때 특히 유용한 옵션은 Copilot CLI을 참조하세요.

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 security 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

참고

Gists는 Enterprise Managed Users사용자가 사용할 수 없으며, 데이터 레지던시(*.ghe.com)가 적용된 GitHub Enterprise Cloud를 사용하는 경우에도 이용할 수 없습니다.

셸 스크립팅 패턴

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

추가 읽기