{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiecvdjfid6icvbizoloq2nx3myxszzjr2komowcasiur25ohkmlka",
    "uri": "at://did:plc:52fueo45volmi2dp2qk7tpnf/app.bsky.feed.post/3mg6zbil35sd2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreidnhbhyqg7lco72p2ma72feccspc274tii5i5vmnkhf5nythw462m"
    },
    "mimeType": "image/png",
    "size": 14109
  },
  "path": "/2026/03/set-safe-defaults-for-flags.html",
  "publishedAt": "2026-03-03T14:47:00.000Z",
  "site": "http://testing.googleblog.com",
  "tags": [
    "Tech on the Toilet",
    "printer-friendly version"
  ],
  "textContent": "This article was adapted from a Google Tech on the Toilet (TotT) episode. You can download a printer-friendly version of this TotT episode and post it in your office.\n\n\n\n\nBy Zhe Lu\n\n\n\n\nWe all make mistakes. But big mistakes can cause big headaches! Suppose you're writing a utility to update production data for a launch. Before making changes to production data, you want to perform a dry run to validate the expected changes. In your excitement, you forget to include the --dry_run flag in your command:\n\n$ /scripts/credit_accounts --amount=USD10  # Oops, I forgot to include --dry_run\n---\n\nYou realize your mistake too late. Safe flag defaults can prevent a simple mistake from turning into a major outage:\n\n_Flag has unsafe default:_\n---\ncliArgs.addBoolFlag(name=\"dry_run\", default=False, help=\"If set, print change summary, but do NOT change data.\")\n_Flag has safe default:_\ncliArgs.addBoolFlag(name=\"dry_run\", default=True, help=\"If set, print change summary, but do NOT change data.\")\n\nSafety depends on context: When defining flags, choose the default that minimizes the cost of potential mistakes. This might involve defaulting to a \"dry\" run, asking for user confirmation before irreversible actions, requiring a confirmation flag on the command line, or other strategies. If you’re writing documentation that contains commands, always set values to minimize the damage if run blindly:\n\nFlag in documentation has unsafe default:\n---\n## How to commit changes\nUse this command to commit changes. Use --dry_run to test and compute and report changes.\n```shell/scripts/credit_accounts --amount=[value] --filter=[conditions]```\nFlag in documentation has safe default:\n## How to commit changes\nUse this command to compute and report changes. Use --nodry_run to commit the changes.\n```shell/scripts/credit_accounts --amount=[value] --filter=[conditions]```\n\nSimilarly, consider requiring that environment-specific flags (e.g., backend addresses and output folders) be explicitly set. In this situation, unspecified environment flags will crash your program, instead of potentially mixing configuration across environments.",
  "title": "Set Safe Defaults for Flags",
  "updatedAt": "2026-03-03T14:47:35.748Z"
}