Skip to content

Commit

Permalink
integrate Click framework (#1)
Browse files Browse the repository at this point in the history
* 初步集成click

* 检查路径不存在的情况
  • Loading branch information
zlrs authored Aug 26, 2020
1 parent 51003c5 commit 6d3e253
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions xc
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
#!/usr/bin/python3
import sys
import os


def help_message():
return """Xcode Opener
A CLI tool that opens XCode project from Terminal.
Auto detect `.xcodeproj` file or `.xcworkspace` file.
For example, use it to quickly open a workspace after `pod install`.
Usage:
xc [<XCode_project_directory>]
Options:
-h, --help Show this help"""
import click


def getXCodeProjectOrWorkspaceFilePath(dirPath) -> str:
def hasSameFileName(file1: str, file2: str) -> bool:
basename1 = os.path.basename(file1)
basename2 = os.path.basename(file2)
return os.path.splitext(basename1)[0] == os.path.splitext(basename2)[0]

def chooseFromPrompt(workspaceFile: [str], projectFile: [str]) -> str:
files = workspaceFile + projectFile
prompt = ''
Expand Down Expand Up @@ -73,17 +61,24 @@ def openInXcode(dirPath):
print('No .xcodeproj / .xcworkspace file is found. ')


def main():
if(len(sys.argv) <= 1 or sys.argv[1] == '.'):
cwd = os.getcwd()
elif(sys.argv[1] in ['-h', '--help']):
print(help_message())
return
@click.command()
@click.argument('path', default='.')
def xc(path=''):
"""A CLI tool that opens XCode project from Terminal.
Auto detect `.xcodeproj` file or `.xcworkspace` file.
For example, use it to quickly open a workspace after `pod install`.
"""
if path == '':
path = os.getcwd()

abs_path = os.path.abspath(path)

if os.path.exists(abs_path):
openInXcode(abs_path)
else:
cwd = sys.argv[1]
abs_cwd = os.path.abspath(cwd)
openInXcode(abs_cwd)
click.echo('path not exist.')
exit(1)


if(__name__ == '__main__'):
main()
if __name__ == '__main__':
xc()

0 comments on commit 6d3e253

Please sign in to comment.