@@ -115,5 +115,44 @@ def get_access_token():
115
115
console .print (f"[bold red]エラー[/bold red]: { str (e )} " )
116
116
117
117
118
+ @app .command ()
119
+ def get_sites (
120
+ site_id : str | None = typer .Option (None , "--site-id" , "-s" , help = "取得するサイトの ID(省略時は全サイト)" ),
121
+ access_token : str | None = typer .Option (None , "--access-token" , "-a" , help = "アクセストークンを指定して認証する" ),
122
+ expires_on : int | None = typer .Option (
123
+ None , "--expires-on" , "-e" , help = "アクセストークンの有効期限を指定(Unix時間)"
124
+ ),
125
+ ):
126
+ """SharePoint サイトの情報を取得する"""
127
+ console .print ("[bold green]SharePoint サイト[/bold green]の情報を取得します" )
128
+
129
+ async def _get_sites ():
130
+ try :
131
+ client = get_graph_client (access_token = access_token , expires_on = expires_on )
132
+
133
+ if site_id :
134
+ site = await client .sites .by_site_id (site_id ).get ()
135
+ sites = [site ]
136
+ else :
137
+ sites_response = await client .sites .get ()
138
+ sites = sites_response .value if sites_response .value else []
139
+
140
+ # テーブルで表示
141
+ table = Table (title = "SharePoint サイト" )
142
+ table .add_column ("ID" , style = "cyan" )
143
+ table .add_column ("名前" , style = "green" )
144
+ table .add_column ("URL" , style = "blue" )
145
+
146
+ for site in sites :
147
+ table .add_row (site .id , site .name , site .web_url )
148
+
149
+ console .print (table )
150
+
151
+ except Exception as e :
152
+ console .print (f"[bold red]エラー[/bold red]: { str (e )} " )
153
+
154
+ asyncio .run (_get_sites ())
155
+
156
+
118
157
if __name__ == "__main__" :
119
158
app ()
0 commit comments