diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index beffa30..0000000 --- a/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 2 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 9b1c8b1..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -/dist diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 7b84619..0000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "oclif", - "oclif-typescript" - ] -} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index adf22b8..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Publish NPM Package - -on: - push: - tags: - - '*' - -permissions: - id-token: write - contents: read - -jobs: - package: - runs-on: ubuntu-latest - name: Publish NPM Package - - steps: - - name: Cloning repo - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - registry-url: 'https://registry.npmjs.org' # required for trusted publishing - - - run: npm i - - run: npm run build - - run: npx -y npm@latest publish diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c72d0ee..9e75f45 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,31 +2,54 @@ name: Build and Test on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] -jobs: - build_and_test: - concurrency: - group: ${{ github.ref }} - cancel-in-progress: true +permissions: + contents: read - runs-on: ubuntu-latest +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: + test: + name: test (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - - name: Check out repository - uses: actions/checkout@v4 - - - name: Set up Node - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 with: - node-version-file: .nvmrc - registry-url: 'https://registry.npmjs.org' + go-version-file: go.mod + - run: go build ./... + - run: go test -race ./... - - name: Install dependencies - run: npm install - shell: bash + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: go.mod + - uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 + with: + version: v2.11.4 # keep in step with the hook rev in .pre-commit-config.yaml + - run: go mod tidy -diff - - name: Build - run: npm run build + cross-compile: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: go.mod + - name: build release targets + run: | + for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do + echo "building $target" + GOOS=${target%/*} GOARCH=${target#*/} go build -o /dev/null . + done diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml deleted file mode 100644 index 968c75b..0000000 --- a/.github/workflows/release-please.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Update release PR - -on: - push: - branches: - - main - -permissions: - contents: write - pull-requests: write - -jobs: - release-please: - runs-on: ubuntu-latest - steps: - - uses: googleapis/release-please-action@v4 - with: - token: ${{ secrets.RELEASE_PLEASE_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 12865b1..a94b49e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,3 @@ -*-debug.log -*-error.log -/.nyc_output -/dist -/lib -/package-lock.json -/tmp -/yarn.lock -node_modules -oclif.manifest.json -.idea -flagsmith.json +/flagsmith +/dist/ +*.test diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..66e244d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,14 @@ +version: "2" + +linters: + exclusions: + presets: + - std-error-handling + rules: + - path: _test\.go + linters: + - errcheck + +formatters: + enable: + - gofmt diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 4a09d14..0000000 --- a/.mocharc.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "require": [ - "test/helpers/init.js", - "ts-node/register" - ], - "watch-extensions": [ - "ts" - ], - "recursive": true, - "reporter": "spec", - "timeout": 60000 -} diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index a45fd52..0000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -24 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8d319a8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-merge-conflict + + - repo: https://github.com/golangci/golangci-lint + rev: v2.11.4 + hooks: + - id: golangci-lint-full + - id: golangci-lint-fmt + - id: golangci-lint-config-verify + + - repo: local + hooks: + - id: go-mod-tidy + name: go mod tidy -diff + entry: go mod tidy -diff + language: system + files: (^go\.(mod|sum)$)|(\.go$) + pass_filenames: false + - id: go-test + name: go test + entry: go test ./... + language: system + types: [go] + pass_filenames: false + stages: [pre-push] + +ci: + skip: [golangci-lint-full, golangci-lint-config-verify, go-mod-tidy, go-test] diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index 8d6e472..0000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1 +0,0 @@ -{".":"1.1.0"} diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index eafae8c..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,80 +0,0 @@ -# Changelog - -## [1.1.0](https://github.com/Flagsmith/flagsmith-cli/compare/v1.0.0...v1.1.0) (2026-05-27) - - -### Features - -* migrate npm package to [@flagsmith](https://github.com/flagsmith) organization scope ([#40](https://github.com/Flagsmith/flagsmith-cli/issues/40)) ([3b96bf3](https://github.com/Flagsmith/flagsmith-cli/commit/3b96bf33ed5d4397430381c65e9417b216b2e0e8)) - - -### CI - -* add NPM trusted publishing and release please ([#33](https://github.com/Flagsmith/flagsmith-cli/issues/33)) ([d6fe2bc](https://github.com/Flagsmith/flagsmith-cli/commit/d6fe2bc84accaae327d7afe6ac71f86b82337d7c)) -* fix npm trusted publishing ([#36](https://github.com/Flagsmith/flagsmith-cli/issues/36)) ([f76d21c](https://github.com/Flagsmith/flagsmith-cli/commit/f76d21c4e6d9f036237de92a1621fd9994c41346)) - - -### Other - -* Add build and test workflow, fix npm audit issues ([fa5d5da](https://github.com/Flagsmith/flagsmith-cli/commit/fa5d5da19e1ae552ca2c93a9f2473f9287ec9630)) -* **main:** release 0.2.2 ([#34](https://github.com/Flagsmith/flagsmith-cli/issues/34)) ([7759431](https://github.com/Flagsmith/flagsmith-cli/commit/775943112431f5ad40a9b196023c2f466d17a44d)) -* **main:** release 0.2.3 ([#37](https://github.com/Flagsmith/flagsmith-cli/issues/37)) ([80a5064](https://github.com/Flagsmith/flagsmith-cli/commit/80a50645d20af1924ca8f55b1c017bb655e834a3)) -* Remove amannn/action-semantic-pull-request workflow ([#38](https://github.com/Flagsmith/flagsmith-cli/issues/38)) ([a069831](https://github.com/Flagsmith/flagsmith-cli/commit/a0698319d3def4461ac3344a89f30a092b30e48c)) - -## [0.2.3](https://github.com/Flagsmith/flagsmith-cli/compare/v0.2.2...v0.2.3) (2025-11-24) - - -### CI - -* fix npm trusted publishing ([#36](https://github.com/Flagsmith/flagsmith-cli/issues/36)) ([f76d21c](https://github.com/Flagsmith/flagsmith-cli/commit/f76d21c4e6d9f036237de92a1621fd9994c41346)) - -## [0.2.2](https://github.com/Flagsmith/flagsmith-cli/compare/0.2.1...v0.2.2) (2025-11-06) - - -### CI - -* add NPM trusted publishing and release please ([#33](https://github.com/Flagsmith/flagsmith-cli/issues/33)) ([d6fe2bc](https://github.com/Flagsmith/flagsmith-cli/commit/d6fe2bc84accaae327d7afe6ac71f86b82337d7c)) - - -### Other - -* Add build and test workflow, fix npm audit issues ([fa5d5da](https://github.com/Flagsmith/flagsmith-cli/commit/fa5d5da19e1ae552ca2c93a9f2473f9287ec9630)) - - -## [0.2.1 - Update Flagsmith sdk](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.2.1) - 2025-03-20 - -Merges [#25](https://github.com/Flagsmith/flagsmith-cli/pull/25) - -[Changes][0.2.1] - - - -## [0.1.3 - Adds prettify flag -p](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.3) - 2023-05-29 - -[#12](https://github.com/Flagsmith/flagsmith-cli/pull/12) - -[Changes][0.1.3] - - - -## [0.1.2 - Add Identity flag -i](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.2) - 2023-05-29 - -[#11](https://github.com/Flagsmith/flagsmith-cli/pull/11) - -[Changes][0.1.2] - - - -## [0.1.1 - Fix api-input in a wrong const](https://github.com/Flagsmith/flagsmith-cli/releases/tag/0.1.1) - 2023-01-20 - -Merges [#10](https://github.com/Flagsmith/flagsmith-cli/pull/10), thank you very much [@vladaCizek](https://github.com/vladaCizek)! ๐Ÿš€ - -[Changes][0.1.1] - - -[0.2.1]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.3...0.2.1 -[0.1.3]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.2...0.1.3 -[0.1.2]: https://github.com/Flagsmith/flagsmith-cli/compare/0.1.1...0.1.2 -[0.1.1]: https://github.com/Flagsmith/flagsmith-cli/tree/0.1.1 - - diff --git a/README.md b/README.md index 0e7e3cc..e5c9f88 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,67 @@ - +# Flagsmith CLI -@flagsmith/cli -================= +The next-generation Flagsmith command-line interface (work in progress). -Retrieve Flagsmith state from an API and store it in a file. +## Build -This CLI can be used to bake default flags into your application as part of CI/CD, this provides support for offline applications and is also advised as part of our [Defensive Coding and Default Flags Documentation](https://docs.flagsmith.com/guides-and-examples/defensive-coding). An example of this can be seen [here](./example). - - -# Populating defaultFlags in your Project - -The steps to using this to provide default flags are as follows. An example of this can be found [here](./example). The main steps to achieving this are as follows: - - -1. Install the cli ``npm i @flagsmith/cli --save-dev`` -2. Call the cli as part of postinstall to create a ``flagsmith.json`` file: - -```export FLAGSMITH_ENVIRONMENT=API_KEY``` - -``` -"postinstall": "flagsmith get" -``` -An example of this can be seen [here](./example/src/index.tsx). -3. In your application, import the outputted JSON and initialise the client with the json ``flagsmith.init({state:json, environmentID: json.environmentID})`` - -**Example:** - -```typescript -import flagsmith from '@flagsmith/flagsmith' -import state from './flagsmith.json' - -flagsmith.init({state, environmentID: state.environmentID}) -``` - -**Example with React:** - -```jsx -import state from './flagsmith.json' -ReactDOM.render( - - - , - document.getElementById('root') -); +```sh +go build -o flagsmith . ``` - -# Usage - Global - -```sh-session -$ npm install -g @flagsmith/cli -$ flagsmith COMMAND -running command... -$ flagsmith (--version) -flagsmith-cli/0.1.2 darwin-arm64 node-v18.13.0 -$ flagsmith --help [COMMAND] -USAGE - $ flagsmith COMMAND -... -``` - -# Commands - -* [`flagsmith get [ENVIRONMENT]`](#flagsmith-get-environment) -* [`flagsmith help [COMMANDS]`](#flagsmith-help-commands) - -## `flagsmith get [ENVIRONMENT]` - -Retrieve flagsmith features from the Flagsmith API and output them to a file. +## Quickstart +```sh +flagsmith init # log in, pick a project + environment, write flagsmith.json +flagsmith flag list # list the flags in the current environment ``` -USAGE - $ flagsmith get [ENVIRONMENT] [-o ] [-a ] [-t - -i ] [-p] [-e flags|environment] - -ARGUMENTS - ENVIRONMENT The flagsmith environment key to use, defaults to the environment - variable FLAGSMITH_ENVIRONMENT - -FLAGS - -a, --api= [default: https://edge.api.flagsmith.com/api/v1/] The - API URL to fetch the feature flags from - -e, --entity=