Skip to content

Commit

Permalink
wip: add CLI functionality, improves old CLI adding target setting op…
Browse files Browse the repository at this point in the history
…tionally
  • Loading branch information
kronenthaler committed Dec 11, 2016
1 parent 5a579ec commit 3952190
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -10,8 +10,7 @@ install:
- pip install scrutinizer-ocular

script:
- python setup.py test
- coverage run --branch --source=pbxproj setup.py test
- python setup.py coverage

after_success:
- coveralls
Expand Down
54 changes: 54 additions & 0 deletions pbxproj/__main__.py
@@ -0,0 +1,54 @@
from pbxproj import XcodeProject


def main():
import argparse
import os

parser = argparse.ArgumentParser("Modify an XCode project file using a single command at a time.")
parser.add_argument('project', help="Project path")
parser.add_argument('-t', '--target', help="Target to modify", default=None)
parser.add_argument('-c', '--configuration', help="Configuration to modify", choices=['Debug', 'Release'], default=None)
parser.add_argument('-af', help='Add a flag value, in the format key=value', action='append')
parser.add_argument('-rf', help='Remove a flag value, in the format key=value', action='append')
parser.add_argument('-b', '--backup', help='Create a temporary backup before modify', action='store_true')
args = parser.parse_args()

print args

# open the project file
if os.path.isdir(args.project):
args.project += "/project.pbxproj"

if not os.path.isfile(args.project):
raise Exception("Project File not found")

project = XcodeProject.load(args.project)
backup_file = None
if args.backup :
backup_file = project.backup()

# apply the commands
# add flags
if args.af:
pairs = {}
for flag in args.af:
tokens = flag.split("=")
project.add_flags(tokens[0], tokens[1],target_name=args.target, configuration_name=args.configuration)

# remove flags
if args.rf:
pairs = {}
for flag in args.rf:
tokens = flag.split("=")
project.remove_flags(tokens[0], tokens[1], target_name=args.target, configuration_name=args.configuration)

# save the file
project.save()

# remove backup if everything was ok.
if args.backup:
os.remove(backup_file)

if __name__ == "__main__":
main()
54 changes: 27 additions & 27 deletions readme.md
Expand Up @@ -6,35 +6,35 @@ This module can read, modify, and write a .pbxproj file from an Xcode 4, 5 & 6 p
## Table of Contents
* [Table of Contents](#table-of-contents)
* [Installation](#installation)
* [Using pip](#using-pip)
* [Using setup.py](#using-setuppy)
* [Using pip](#using-pip)
* [Using setup.py](#using-setuppy)
* [Using as CLI](#using-as-cli)
* [CLI options](#cli-options)
* [CLI options](#cli-options)
* [Basic usage](#basic-usage)
* [Import the module](#import-the-module)
* [Load & Write](#load--write)
* [Load a project file](#load-a-project-file)
* [Create a backup](#create-a-backup)
* [Save the project](#save-the-project)
* [Groups](#groups)
* [Create or get a group](#create-or-get-a-group)
* [Create groups recursively](#create-groups-recursively)
* [Remove group by ID](#remove-group-by-id)
* [Remove group by name](#remove-group-by-name)
* [Files](#files)
* [Add files](#add-files)
* [Add a library/framework](#add-a-libraryframework)
* [Remove files by ID](#remove-files-by-id)
* [Remove files by path](#remove-files-by-path)
* [Flags](#flags)
* [Add a flag](#add-a-flag)
* [Compiler flags](#compiler-flags)
* [Linker flags](#linker-flags)
* [Any other flags](#any-other-flags)
* [Remove flags from a list of flags](#remove-flags-from-a-list-of-flags)
* [Single-valued flags](#single-valued-flags)
* [Only modifying some build configurations](#only-modifying-some-build-configurations)
* [Per-file flags](#per-file-flags)
* [Import the module](#import-the-module)
* [Load & Write](#load--write)
* [Load a project file](#load-a-project-file)
* [Create a backup](#create-a-backup)
* [Save the project](#save-the-project)
* [Groups](#groups)
* [Create or get a group](#create-or-get-a-group)
* [Create groups recursively](#create-groups-recursively)
* [Remove group by ID](#remove-group-by-id)
* [Remove group by name](#remove-group-by-name)
* [Files](#files)
* [Add files](#add-files)
* [Add a library/framework](#add-a-libraryframework)
* [Remove files by ID](#remove-files-by-id)
* [Remove files by path](#remove-files-by-path)
* [Flags](#flags)
* [Add a flag](#add-a-flag)
* [Compiler flags](#compiler-flags)
* [Linker flags](#linker-flags)
* [Any other flags](#any-other-flags)
* [Remove flags from a list of flags](#remove-flags-from-a-list-of-flags)
* [Single-valued flags](#single-valued-flags)
* [Only modifying some build configurations](#only-modifying-some-build-configurations)
* [Per-file flags](#per-file-flags)


## Installation
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -32,7 +32,7 @@ def run_tests(self):
'-w', 'tests'])


setup(name='mod_pbxproj',
setup(name='pbxproj',
author='Ignacio Calderon',
description='XCode Project manipulation library for Python',
url="http://github.com/kronenthaler/mod-pbxproj",
Expand Down

0 comments on commit 3952190

Please sign in to comment.