Skip to main content

Protocol Buffers file formatter.

Project description

proto-formatter

Protocol Buffers file formatter.

Install

pip install proto-formatter

Usage

Format all proto files under current folder and sub-folders with default configs

proto_formatter format

Help message

****************************************************************************************************
*                         Format protobuf file(s) from a specific target.                          *
*                                           MIT License                                            *
****************************************************************************************************
usage:
  proto_formatter <command> [options]

commands:
  format                       format protobuf files
  view                         view file

general options:
  -h                           show this help message and exit
  --help                       show this help message and exit
  --files                      target protobuf files need to be formatted.
  --folder                     target directory, default is current directory, all protobuf files
                               under it including all subdirectories will be formatted.
  --preview                    preview formatted protobuf file with syntax highlighting. Default
                               value is False, if it set to True, protobuf files will not be
                               overided by formatted ones.
  --indents                    the number of indented spaces, default is 4
  --top-comment                format all comments as top comments(above the target line), default
                               is False
  --align-by-equal-sign        align the code by equal sign: True or False, default is True
  --flatten                    flatten nested objects, default is False
  --comment-max-length         the max length of comment line, default is 999999.
  --file                       target protobuf file, only used for command 'view'

It also provides a method format_str to format a protobuf string.

from proto_formatter import format_str

proto_str = """
    /*
    Person balabala
*/
    message Person {
    // comment of name a
required string name = 1; // comment of name b
/* 
comment of id a
// comment of id b
         */
        required int32 id = 2;// comment of id c
       optional string email = 3;// comment of email
       //element bottom comment one
       //element bottom comment two
}
//bottom comment one
//bottom comment two
"""
formatted_proto_str = format_str(proto_str)
print(formatted_proto_str)

The formatted_proto_str is:

/*
**    Person balabala
*/
message Person {
  /*
  **    comment of name a
  */
  required string name = 1;   // comment of name b
  /*
  **    comment of id a
  **    comment of id b
  */
  required int32 id = 2;      // comment of id c
  optional string email = 3;  // comment of email
  /*
  **    element bottom comment one
  **    element bottom comment two
  */
}
/*
**    bottom comment one
**    bottom comment two
*/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proto-formatter-0.2.3.tar.gz (20.3 kB view details)

Uploaded Source

File details

Details for the file proto-formatter-0.2.3.tar.gz.

File metadata

  • Download URL: proto-formatter-0.2.3.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.8.2 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.9

File hashes

Hashes for proto-formatter-0.2.3.tar.gz
Algorithm Hash digest
SHA256 50b9ff8f3ce64b2009f8215f0795667c4ab9b2bb8452e82f6f8fb202b5e67d57
MD5 10a97cbcdd4fe1f21e2939f66634b1a1
BLAKE2b-256 7f73bfcceb27e6fe1a623234487f1ab62e5e4a408b1240bab10ac05c086e71fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page