使用範例

實用範例,展示如何使用 Bob Shell 進行除錯、改善程式碼、建立檔案、產生文件及學習新概念。

修正 shell 命令中的錯誤

當您的 shell 命令發生錯誤時,Bob Shell 可以協助診斷並修正:

# 切換至您的專案目錄
cd your-project/

# 啟動 Bob Shell
bob chat

# 切換至 shell 模式
> !

# 輸入造成錯誤的命令
> make build

# 當您看到錯誤訊息,例如 'No rule to make target `xxx', needed by `yyy'.'

# 按 ESC 或再次輸入 '!' 結束 shell 模式

# 向 Bob Shell 請求協助
> Help me to fix the error

程式碼解釋與改善

Bob Shell 可以協助您理解並改善現有程式碼:

# 在您的專案目錄中啟動 Bob Shell
bob chat

# 請求解釋特定檔案
> Explain what @src/utils.js does and how it works

# 請求改善您的程式碼
> Review @src/api.js and suggest improvements for error handling

建立新檔案和功能

使用 Bob Shell 協助您建立新元件或功能:

# 在您的專案目錄中啟動 Bob Shell
bob chat

# 請求協助建立新元件
> Create a React component for a user profile page that displays name, email, and avatar

# 產生工具函式
> Write a utility function that formats dates in YYYY-MM-DD format

除錯協助

Bob Shell 可以協助您除錯程式碼中的問題:

# 在您的專案目錄中啟動 Bob Shell
bob chat

# 與 Bob Shell 分享錯誤日誌
> I'm getting this error when running my app: "TypeError: Cannot read property 'map' of undefined". Here's the relevant code: @src/components/List.js

# 或直接將錯誤輸出以管道傳給 Bob Shell
# 在您的終端機中(不在 Bob Shell 中)
npm run start 2>&1 | bob run "Help me understand and fix this error"

產生文件

使用 Bob Shell 為您的程式碼產生文件:

# 在您的專案目錄中啟動 Bob Shell
bob chat

# 為特定檔案產生文件
> Create JSDoc comments for all functions in @src/helpers.js

# 為您的專案產生 README
> Create a README.md file for my project based on the code in @src/index.js

學習新概念

使用 Bob Shell 學習新技術或概念:

# 啟動 Bob Shell
bob chat

# 詢問特定技術
> Explain how React hooks work and give me examples of useState and useEffect

# 學習設計模式
> Explain the Observer pattern and how I might implement it in JavaScript
這個主題如何?