How to add build_flags from CLI or script?

Hey Guys,

I’m currently working on a project where I need to initialize Platformio projects from a python script.
To make it I’m using the pio project init command line, and I was wondering if there is any way to use this command to add stuff such as build_flags or lib_deps?

For example this command: pio project init --environment native -O="platform=native" -O="build_flags=-lpthread" give me this platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:native]
platform = native
build_flags = -lpthread

Then I would like to be able to add something in the build_flags
for example by using: pio project init --environment native -O="build_flags=-lm", the output platformio.ini`would be:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:native]
platform = native
build_flags =
    -lpthread
    -lm

Alternatively, I see that it is possible to extract the platformio.ini as Json format using the pio project config --json-output. It would be very practical to be able to get this Json, modify it as we want, then re-inject it somewhere to regenerate the platformio.ini file.

Is there anything existing allowing to solve this?